Instrument Prometheus query times

This commit instruments prometheus query times by prometheus endpoint,
allowing us to see how quickly prometheus answers the queries that
back the custom-metrics API endpoints.
This commit is contained in:
Solly Ross 2017-06-02 15:07:13 -04:00
parent 5bff503339
commit 3690c3ac6b
2 changed files with 84 additions and 1 deletions

View file

@ -33,6 +33,7 @@ import (
"k8s.io/custom-metrics-boilerplate/pkg/cmd/server"
cmprov "github.com/directxman12/k8s-prometheus-adapter/pkg/custom-provider"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
mprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/metrics"
)
// NewCommandStartPrometheusAdapterServer provides a CLI handler for 'start master' command
@ -87,6 +88,8 @@ func (o PrometheusAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-c
return err
}
config.GenericConfig.EnableMetrics = true
var clientConfig *rest.Config
if len(o.RemoteKubeConfigFile) > 0 {
loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
@ -122,7 +125,9 @@ func (o PrometheusAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-c
if err != nil {
return fmt.Errorf("invalid Prometheus URL %q: %v", baseURL, err)
}
promClient := prom.NewClient(http.DefaultClient, baseURL)
genericPromClient := prom.NewGenericAPIClient(http.DefaultClient, baseURL)
instrumentedGenericPromClient := mprom.InstrumentGenericAPIClient(genericPromClient, baseURL.String())
promClient := prom.NewClientForAPI(instrumentedGenericPromClient)
cmProvider := cmprov.NewPrometheusProvider(dynamicMapper, clientPool, promClient, o.MetricsRelistInterval, o.RateInterval)