Adding Prometheus metrics, refactoring code
This commit is contained in:
@@ -3,12 +3,12 @@ package varnish
|
||||
|
||||
import (
|
||||
"context"
|
||||
prometheus2 "http-broadcaster/Prometheus"
|
||||
vault "http-broadcaster/Vault"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
vault "http-broadcaster/Vault"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,8 +31,10 @@ func InitializeVarnishList() []string {
|
||||
// GetVarnishListFromVault builds a list of varnish servers from Vault.
|
||||
func GetVarnishListFromVault() []string {
|
||||
var value []string
|
||||
vaultDatabase := os.Getenv("VAULT_DATABASE")
|
||||
vaultPath := os.Getenv("VAULT_PATH")
|
||||
client := vault.InitVaultConnection()
|
||||
secret, err := client.KVv2("app").Get(context.Background(), "http-broadcaster/stg/envVars")
|
||||
secret, err := client.KVv2(vaultDatabase).Get(context.Background(), vaultPath)
|
||||
if err != nil {
|
||||
log.Fatal("unable to read secret: %w", err)
|
||||
return value
|
||||
@@ -50,7 +52,7 @@ func GetVarnishListFromVault() []string {
|
||||
|
||||
// GetVarnishListFromFile reads the list of varnish servers from a file on disk.
|
||||
func GetVarnishListFromFile() []string {
|
||||
Data, err := os.ReadFile("./varnish")
|
||||
Data, err := os.ReadFile("./varnish_list")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -80,9 +82,11 @@ func SendToVarnish(method string, url string, tag string) string {
|
||||
if err != nil {
|
||||
log.Fatal("Send new request : ", err)
|
||||
}
|
||||
prometheus2.IncrementBackendCounterVec(method)
|
||||
if resp.StatusCode != 200 {
|
||||
status = "405 Not Allowed"
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user