in custom-metrics-stackdriver-adapter/adapter.go [85:132]
func (sa *StackdriverAdapter) makeProviderOrDie(o *stackdriverAdapterServerOptions, rateInterval time.Duration, alignmentPeriod time.Duration) (provider.MetricsProvider, *translator.Translator) {
config, err := sa.ClientConfig()
if err != nil {
klog.Fatalf("unable to construct client config: %v", err)
}
client, err := coreclient.NewForConfig(config)
if err != nil {
klog.Fatalf("unable to construct client: %v", err)
}
mapper, err := sa.RESTMapper()
if err != nil {
klog.Fatalf("unable to construct discovery REST mapper: %v", err)
}
tokenSource, err := google.DefaultTokenSource(oauth2.NoContext, "https://www.googleapis.com/auth/monitoring.read")
if err != nil {
klog.Fatalf("unable to use default token source: %v", err)
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
stackdriverService, err := stackdriver.New(oauthClient)
if err != nil {
klog.Fatalf("Failed to create Stackdriver client: %v", err)
}
if o.StackdriverEndpoint != "" {
if !validateUrl(o.StackdriverEndpoint) {
klog.Fatalf("Provided StackdriverEndpoint %v is not correct url", o.StackdriverEndpoint)
}
stackdriverService.BasePath = o.StackdriverEndpoint
}
gceConf, err := gceconfig.GetGceConfig()
if err != nil {
klog.Fatalf("Failed to retrieve GCE config: %v", err)
}
conf, err := sa.Config()
if err != nil {
klog.Fatalf("Unable to get StackdriverAdapter apiserver config %v", err)
}
conf.GenericConfig.EnableMetrics = true
translator := translator.NewTranslator(stackdriverService, gceConf, rateInterval, alignmentPeriod, mapper, o.UseNewResourceModel, o.EnableDistributionSupport)
// If ListFullCustomMetrics is false, it returns one resource during api discovery `kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta2"` to reduce memory usage.
customMetricsListCache := listStackdriverCustomMetrics(translator, o.ListFullCustomMetrics, o.FallbackForContainerMetrics)
return adapter.NewStackdriverProvider(client, mapper, gceConf, stackdriverService, translator, rateInterval, o.UseNewResourceModel, o.FallbackForContainerMetrics, customMetricsListCache, o.ExternalMetricsCacheTTL, o.ExternalMetricsCacheSize), translator
}