diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index a9b7036000..934438c3dd 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -29,7 +29,6 @@ import ( "github.com/nginxinc/nginx-plus-go-client/client" nginxCollector "github.com/nginxinc/nginx-prometheus-exporter/collector" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/common/promlog" api_v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" util_version "k8s.io/apimachinery/pkg/util/version" @@ -39,6 +38,9 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" + + kitlog "github.com/go-kit/log" + "github.com/go-kit/log/level" ) // Injected during build @@ -739,15 +741,8 @@ func createPlusAndLatencyCollectors( streamServerZoneVariableLabels := []string{"resource_type", "resource_name", "resource_namespace"} variableLabelNames := nginxCollector.NewVariableLabelNames(upstreamServerVariableLabels, serverZoneVariableLabels, upstreamServerPeerVariableLabelNames, streamUpstreamServerVariableLabels, streamServerZoneVariableLabels, streamUpstreamServerPeerVariableLabelNames, nil, nil) - infoLevel := new(promlog.AllowedLevel) - err := infoLevel.Set("info") - if err != nil { - glog.Error("Error setting prometheus exporter log level") - } - promlogConfig := &promlog.Config{ - Level: infoLevel, - } - logger := promlog.New(promlogConfig) + logger := kitlog.NewLogfmtLogger(os.Stdout) + logger = level.NewFilter(logger, level.AllowError()) plusCollector = nginxCollector.NewNginxPlusCollector(plusClient, "nginx_ingress_nginxplus", variableLabelNames, constLabels, logger) go metrics.RunPrometheusListenerForNginxPlus(*prometheusMetricsListenPort, plusCollector, registry, prometheusSecret) } else { diff --git a/go.mod b/go.mod index 14a0a94cc9..40d6f36014 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/dlclark/regexp2 v1.11.2 github.com/gkampitakis/go-snaps v0.5.4 github.com/go-chi/chi/v5 v5.1.0 + github.com/go-kit/log v0.2.1 github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang/glog v1.2.0 github.com/google/go-cmp v0.6.0 @@ -19,7 +20,6 @@ require ( github.com/nginxinc/nginx-service-mesh v1.7.0 github.com/nginxinc/telemetry-exporter v0.1.0 github.com/prometheus/client_golang v1.18.0 - github.com/prometheus/common v0.47.0 github.com/spiffe/go-spiffe/v2 v2.3.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/otel v1.28.0 @@ -63,7 +63,6 @@ require ( github.com/gkampitakis/go-diff v1.3.2 // indirect github.com/go-asn1-ber/asn1-ber v1.5.6 // indirect github.com/go-jose/go-jose/v4 v4.0.2 // indirect - github.com/go-kit/log v0.2.1 // indirect github.com/go-ldap/ldap/v3 v3.4.8 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-logr/logr v1.4.2 // indirect @@ -96,6 +95,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.47.0 // indirect github.com/prometheus/procfs v0.15.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/spf13/cobra v1.8.0 // indirect diff --git a/internal/metrics/listener.go b/internal/metrics/listener.go index 65e3e2b4e4..6d1dc553f1 100644 --- a/internal/metrics/listener.go +++ b/internal/metrics/listener.go @@ -6,16 +6,18 @@ import ( "errors" "fmt" "net/http" + "os" "strconv" "time" "github.com/go-chi/chi/v5" + kitlog "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/golang/glog" prometheusClient "github.com/nginxinc/nginx-prometheus-exporter/client" nginxCollector "github.com/nginxinc/nginx-prometheus-exporter/collector" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/promlog" v1 "k8s.io/api/core/v1" ) @@ -26,16 +28,8 @@ func NewNginxMetricsClient(httpClient *http.Client) *prometheusClient.NginxClien // RunPrometheusListenerForNginx runs an http server to expose Prometheus metrics for NGINX func RunPrometheusListenerForNginx(port int, client *prometheusClient.NginxClient, registry *prometheus.Registry, constLabels map[string]string, prometheusSecret *v1.Secret) { - infoLevel := new(promlog.AllowedLevel) - err := infoLevel.Set("info") - if err != nil { - glog.Error("Error setting prometheus exporter log level") - } - promlogConfig := &promlog.Config{ - Level: infoLevel, - } - - logger := promlog.New(promlogConfig) + logger := kitlog.NewLogfmtLogger(os.Stdout) + logger = level.NewFilter(logger, level.AllowError()) registry.MustRegister(nginxCollector.NewNginxCollector(client, "nginx_ingress_nginx", constLabels, logger)) runServer(strconv.Itoa(port), registry, prometheusSecret) }