revert changes

This commit is contained in:
Vivek Kumar 2024-04-10 12:05:43 +05:30
parent 5af792b7d6
commit 2621acaf1d
No known key found for this signature in database
GPG key ID: 81605FDFBA4EF440

View file

@ -45,32 +45,14 @@ var (
}, },
[]string{"path", "server"}, []string{"path", "server"},
) )
// define a counter for API errors for various ErrorTypes
apiErrorCount = metrics.NewCounterVec(
&metrics.CounterOpts{
Namespace: "prometheus_adapter",
Subsystem: "prometheus_client",
Name: "api_errors_total",
Help: "Total number of API errors",
},
[]string{"error_code", "path", "server"},
)
) )
func MetricsHandler() (http.HandlerFunc, error) { func MetricsHandler() (http.HandlerFunc, error) {
registry := metrics.NewKubeRegistry() registry := metrics.NewKubeRegistry()
err := registry.Register(queryLatency)
errRegisterQueryLatency := registry.Register(queryLatency) if err != nil {
if errRegisterQueryLatency != nil { return nil, err
return nil, errRegisterQueryLatency
} }
errRegisterAPIErrorCount := registry.Register(apiErrorCount)
if errRegisterAPIErrorCount != nil {
return nil, errRegisterAPIErrorCount
}
apimetrics.Register() apimetrics.Register()
return func(w http.ResponseWriter, req *http.Request) { return func(w http.ResponseWriter, req *http.Request) {
legacyregistry.Handler().ServeHTTP(w, req) legacyregistry.Handler().ServeHTTP(w, req)
@ -92,15 +74,11 @@ func (c *instrumentedGenericClient) Do(ctx context.Context, verb, endpoint strin
endTime := time.Now() endTime := time.Now()
// skip calls where we don't make the actual request // skip calls where we don't make the actual request
if err != nil { if err != nil {
if apiErr, wasAPIErr := err.(*client.Error); wasAPIErr { if _, wasAPIErr := err.(*client.Error); !wasAPIErr {
// Measure API errors // TODO: measure API errors by code?
apiErrorCount.With(prometheus.Labels{"error_code": string(apiErr.Type), "path": endpoint, "server": c.serverName}).Inc()
} else {
// Increment a generic error code counter
apiErrorCount.With(prometheus.Labels{"error_code": "generic", "path": endpoint, "server": c.serverName}).Inc()
}
return return
} }
}
queryLatency.With(prometheus.Labels{"path": endpoint, "server": c.serverName}).Observe(endTime.Sub(startTime).Seconds()) queryLatency.With(prometheus.Labels{"path": endpoint, "server": c.serverName}).Observe(endTime.Sub(startTime).Seconds())
}() }()