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"},
)
// 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) {
registry := metrics.NewKubeRegistry()
errRegisterQueryLatency := registry.Register(queryLatency)
if errRegisterQueryLatency != nil {
return nil, errRegisterQueryLatency
err := registry.Register(queryLatency)
if err != nil {
return nil, err
}
errRegisterAPIErrorCount := registry.Register(apiErrorCount)
if errRegisterAPIErrorCount != nil {
return nil, errRegisterAPIErrorCount
}
apimetrics.Register()
return func(w http.ResponseWriter, req *http.Request) {
legacyregistry.Handler().ServeHTTP(w, req)
@ -92,14 +74,10 @@ func (c *instrumentedGenericClient) Do(ctx context.Context, verb, endpoint strin
endTime := time.Now()
// skip calls where we don't make the actual request
if err != nil {
if apiErr, wasAPIErr := err.(*client.Error); wasAPIErr {
// Measure API errors
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
if _, wasAPIErr := err.(*client.Error); !wasAPIErr {
// TODO: measure API errors by code?
return
}
}
queryLatency.With(prometheus.Labels{"path": endpoint, "server": c.serverName}).Observe(endTime.Sub(startTime).Seconds())
}()