Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace promlog with go-kit #6053

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -736,15 +738,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 {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions internal/metrics/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
Expand Down
Loading