mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-05 17:27:51 +00:00
*: replace glog with klog
This commit is contained in:
parent
f69586b71c
commit
f18b6fd370
9 changed files with 49 additions and 49 deletions
|
|
@ -27,7 +27,6 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
resmetrics "github.com/kubernetes-incubator/metrics-server/pkg/apiserver/generic"
|
||||
|
|
@ -36,6 +35,7 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/transport"
|
||||
"k8s.io/component-base/logs"
|
||||
"k8s.io/klog"
|
||||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
mprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/metrics"
|
||||
|
|
@ -83,14 +83,14 @@ func (cmd *PrometheusAdapter) makePromClient() (prom.Client, error) {
|
|||
return nil, err
|
||||
}
|
||||
httpClient = prometheusCAClient
|
||||
glog.Info("successfully loaded ca from file")
|
||||
klog.Info("successfully loaded ca from file")
|
||||
} else {
|
||||
kubeconfigHTTPClient, err := makeKubeconfigHTTPClient(cmd.PrometheusAuthInCluster, cmd.PrometheusAuthConf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
httpClient = kubeconfigHTTPClient
|
||||
glog.Info("successfully using in-cluster auth")
|
||||
klog.Info("successfully using in-cluster auth")
|
||||
}
|
||||
|
||||
if cmd.PrometheusTokenFile != "" {
|
||||
|
|
@ -246,26 +246,26 @@ func main() {
|
|||
}
|
||||
cmd.Name = "prometheus-metrics-adapter"
|
||||
cmd.addFlags()
|
||||
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the glog flags
|
||||
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
|
||||
if err := cmd.Flags().Parse(os.Args); err != nil {
|
||||
glog.Fatalf("unable to parse flags: %v", err)
|
||||
klog.Fatalf("unable to parse flags: %v", err)
|
||||
}
|
||||
|
||||
// make the prometheus client
|
||||
promClient, err := cmd.makePromClient()
|
||||
if err != nil {
|
||||
glog.Fatalf("unable to construct Prometheus client: %v", err)
|
||||
klog.Fatalf("unable to construct Prometheus client: %v", err)
|
||||
}
|
||||
|
||||
// load the config
|
||||
if err := cmd.loadConfig(); err != nil {
|
||||
glog.Fatalf("unable to load metrics discovery config: %v", err)
|
||||
klog.Fatalf("unable to load metrics discovery config: %v", err)
|
||||
}
|
||||
|
||||
// construct the provider
|
||||
cmProvider, err := cmd.makeProvider(promClient, wait.NeverStop)
|
||||
if err != nil {
|
||||
glog.Fatalf("unable to construct custom metrics provider: %v", err)
|
||||
klog.Fatalf("unable to construct custom metrics provider: %v", err)
|
||||
}
|
||||
|
||||
// attach the provider to the server, if it's needed
|
||||
|
|
@ -276,7 +276,7 @@ func main() {
|
|||
// construct the external provider
|
||||
emProvider, err := cmd.makeExternalProvider(promClient, wait.NeverStop)
|
||||
if err != nil {
|
||||
glog.Fatalf("unable to construct external metrics provider: %v", err)
|
||||
klog.Fatalf("unable to construct external metrics provider: %v", err)
|
||||
}
|
||||
|
||||
// attach the provider to the server, if it's needed
|
||||
|
|
@ -286,12 +286,12 @@ func main() {
|
|||
|
||||
// attach resource metrics support, if it's needed
|
||||
if err := cmd.addResourceMetricsAPI(promClient); err != nil {
|
||||
glog.Fatalf("unable to install resource metrics API: %v", err)
|
||||
klog.Fatalf("unable to install resource metrics API: %v", err)
|
||||
}
|
||||
|
||||
// run the server
|
||||
if err := cmd.Run(wait.NeverStop); err != nil {
|
||||
glog.Fatalf("unable to run custom metrics adapter: %v", err)
|
||||
klog.Fatalf("unable to run custom metrics adapter: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/common/model"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// APIClient is a raw client to the Prometheus Query API.
|
||||
|
|
@ -70,8 +70,8 @@ func (c *httpAPIClient) Do(ctx context.Context, verb, endpoint string, query url
|
|||
return APIResponse{}, err
|
||||
}
|
||||
|
||||
if glog.V(6) {
|
||||
glog.Infof("%s %s %s", verb, u.String(), resp.Status)
|
||||
if klog.V(6) {
|
||||
klog.Infof("%s %s %s", verb, u.String(), resp.Status)
|
||||
}
|
||||
|
||||
code := resp.StatusCode
|
||||
|
|
@ -85,12 +85,12 @@ func (c *httpAPIClient) Do(ctx context.Context, verb, endpoint string, query url
|
|||
}
|
||||
|
||||
var body io.Reader = resp.Body
|
||||
if glog.V(8) {
|
||||
if klog.V(8) {
|
||||
data, err := ioutil.ReadAll(body)
|
||||
if err != nil {
|
||||
return APIResponse{}, fmt.Errorf("unable to log response body: %v", err)
|
||||
}
|
||||
glog.Infof("Response Body: %s", string(data))
|
||||
klog.Infof("Response Body: %s", string(data))
|
||||
body = bytes.NewReader(data)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider/helpers"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
|
|
@ -34,6 +33,7 @@ import (
|
|||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
|
|
@ -125,13 +125,13 @@ func (p *prometheusProvider) buildQuery(info provider.CustomMetricInfo, namespac
|
|||
// TODO: use an actual context
|
||||
queryResults, err := p.promClient.Query(context.TODO(), pmodel.Now(), query)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||
// don't leak implementation details to the user
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("unable to fetch metrics"))
|
||||
}
|
||||
|
||||
if queryResults.Type != pmodel.ValVector {
|
||||
glog.Errorf("unexpected results from prometheus: expected %s, got %s on results %v", pmodel.ValVector, queryResults.Type, queryResults)
|
||||
klog.Errorf("unexpected results from prometheus: expected %s, got %s on results %v", pmodel.ValVector, queryResults.Type, queryResults)
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("unable to fetch metrics"))
|
||||
}
|
||||
|
||||
|
|
@ -156,12 +156,12 @@ func (p *prometheusProvider) GetMetricByName(name types.NamespacedName, info pro
|
|||
}
|
||||
|
||||
if len(namedValues) > 1 {
|
||||
glog.V(2).Infof("Got more than one result (%v results) when fetching metric %s for %q, using the first one with a matching name...", len(queryResults), info.String(), name)
|
||||
klog.V(2).Infof("Got more than one result (%v results) when fetching metric %s for %q, using the first one with a matching name...", len(queryResults), info.String(), name)
|
||||
}
|
||||
|
||||
resultValue, nameFound := namedValues[name.Name]
|
||||
if !nameFound {
|
||||
glog.Errorf("None of the results returned by when fetching metric %s for %q matched the resource name", info.String(), name)
|
||||
klog.Errorf("None of the results returned by when fetching metric %s for %q matched the resource name", info.String(), name)
|
||||
return nil, provider.NewMetricNotFoundForError(info.GroupResource, info.Metric, name.Name)
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ func (p *prometheusProvider) GetMetricBySelector(namespace string, selector labe
|
|||
// fetch a list of relevant resource names
|
||||
resourceNames, err := helpers.ListObjectNames(p.mapper, p.kubeClient, namespace, selector, info)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to list matching resource names: %v", err)
|
||||
klog.Errorf("unable to list matching resource names: %v", err)
|
||||
// don't leak implementation details to the user
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("unable to list matching resources"))
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ func (l *cachingMetricsLister) updateMetrics() error {
|
|||
newSeries[i] = namer.FilterSeries(series)
|
||||
}
|
||||
|
||||
glog.V(10).Infof("Set available metric list from Prometheus to: %v", newSeries)
|
||||
klog.V(10).Infof("Set available metric list from Prometheus to: %v", newSeries)
|
||||
|
||||
return l.SetSeries(newSeries, l.namers)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import (
|
|||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
|
||||
"github.com/golang/glog"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// NB: container metrics sourced from cAdvisor don't consistently follow naming conventions,
|
||||
|
|
@ -89,7 +89,7 @@ func (r *basicSeriesRegistry) SetSeries(newSeriesSlices [][]prom.Series, namers
|
|||
resources, namespaced := namer.ResourcesForSeries(series)
|
||||
name, err := namer.MetricNameForSeries(series)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to name series %q, skipping: %v", series.String(), err)
|
||||
klog.Errorf("unable to name series %q, skipping: %v", series.String(), err)
|
||||
continue
|
||||
}
|
||||
for _, resource := range resources {
|
||||
|
|
@ -140,25 +140,25 @@ func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.CustomMetricInf
|
|||
defer r.mu.RUnlock()
|
||||
|
||||
if len(resourceNames) == 0 {
|
||||
glog.Errorf("no resource names requested while producing a query for metric %s", metricInfo.String())
|
||||
klog.Errorf("no resource names requested while producing a query for metric %s", metricInfo.String())
|
||||
return "", false
|
||||
}
|
||||
|
||||
metricInfo, _, err := metricInfo.Normalized(r.mapper)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to normalize group resource while producing a query: %v", err)
|
||||
klog.Errorf("unable to normalize group resource while producing a query: %v", err)
|
||||
return "", false
|
||||
}
|
||||
|
||||
info, infoFound := r.info[metricInfo]
|
||||
if !infoFound {
|
||||
glog.V(10).Infof("metric %v not registered", metricInfo)
|
||||
klog.V(10).Infof("metric %v not registered", metricInfo)
|
||||
return "", false
|
||||
}
|
||||
|
||||
query, err := info.namer.QueryForSeries(info.seriesName, metricInfo.GroupResource, namespace, resourceNames...)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to construct query for metric %s: %v", metricInfo.String(), err)
|
||||
klog.Errorf("unable to construct query for metric %s: %v", metricInfo.String(), err)
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ func (r *basicSeriesRegistry) MatchValuesToNames(metricInfo provider.CustomMetri
|
|||
|
||||
metricInfo, _, err := metricInfo.Normalized(r.mapper)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to normalize group resource while matching values to names: %v", err)
|
||||
klog.Errorf("unable to normalize group resource while matching values to names: %v", err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ func (r *basicSeriesRegistry) MatchValuesToNames(metricInfo provider.CustomMetri
|
|||
|
||||
resourceLbl, err := info.namer.LabelForResource(metricInfo.GroupResource)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to construct resource label for metric %s: %v", metricInfo.String(), err)
|
||||
klog.Errorf("unable to construct resource label for metric %s: %v", metricInfo.String(), err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
"k8s.io/klog"
|
||||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
|
||||
|
|
@ -145,7 +145,7 @@ func (l *basicMetricLister) ListAllMetrics() (MetricUpdateResult, error) {
|
|||
newSeries[i] = namer.FilterSeries(series)
|
||||
}
|
||||
|
||||
glog.V(10).Infof("Set available metric list from Prometheus to: %v", newSeries)
|
||||
klog.V(10).Infof("Set available metric list from Prometheus to: %v", newSeries)
|
||||
|
||||
result.series = newSeries
|
||||
result.namers = l.namers
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ package provider
|
|||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/klog"
|
||||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
|
||||
|
|
@ -68,7 +68,7 @@ func (r *externalSeriesRegistry) filterAndStoreMetrics(result MetricUpdateResult
|
|||
namers := result.namers
|
||||
|
||||
if len(newSeriesSlices) != len(namers) {
|
||||
glog.Fatal("need one set of series per converter")
|
||||
klog.Fatal("need one set of series per converter")
|
||||
}
|
||||
apiMetricsCache := make([]provider.ExternalMetricInfo, 0)
|
||||
rawMetricsCache := make(map[string]seriesInfo)
|
||||
|
|
@ -79,7 +79,7 @@ func (r *externalSeriesRegistry) filterAndStoreMetrics(result MetricUpdateResult
|
|||
identity, err := namer.MetricNameForSeries(series)
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("unable to name series %q, skipping: %v", series.String(), err)
|
||||
klog.Errorf("unable to name series %q, skipping: %v", series.String(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ func (r *externalSeriesRegistry) QueryForMetric(namespace string, metricName str
|
|||
info, found := r.metricsInfo[metricName]
|
||||
|
||||
if !found {
|
||||
glog.V(10).Infof("external metric %q not found", metricName)
|
||||
klog.V(10).Infof("external metric %q not found", metricName)
|
||||
return "", false, nil
|
||||
}
|
||||
query, err := info.namer.QueryForExternalSeries(info.seriesName, namespace, metricSelector)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import (
|
|||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"github.com/golang/glog"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
"k8s.io/klog"
|
||||
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ func (p *externalPrometheusProvider) GetExternalMetric(namespace string, metricS
|
|||
selector, found, err := p.seriesRegistry.QueryForMetric(namespace, info.Metric, metricSelector)
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("unable to generate a query for the metric: %v", err)
|
||||
klog.Errorf("unable to generate a query for the metric: %v", err)
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("unable to fetch metrics"))
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ func (p *externalPrometheusProvider) GetExternalMetric(namespace string, metricS
|
|||
queryResults, err := p.promClient.Query(context.TODO(), pmodel.Now(), selector)
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||
// don't leak implementation details to the user
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("unable to fetch metrics"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ import (
|
|||
|
||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
"github.com/directxman12/k8s-prometheus-adapter/pkg/config"
|
||||
"github.com/golang/glog"
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -185,7 +185,7 @@ func (r *resourceConverter) ResourcesForSeries(series prom.Series) ([]schema.Gro
|
|||
info, _, err := provider.CustomMetricInfo{GroupResource: groupRes}.Normalized(r.mapper)
|
||||
if err != nil {
|
||||
// this is likely to show up for a lot of labels, so make it a verbose info log
|
||||
glog.V(9).Infof("unable to normalize group-resource %s from label %q, skipping: %v", groupRes.String(), lbl, err)
|
||||
klog.V(9).Infof("unable to normalize group-resource %s from label %q, skipping: %v", groupRes.String(), lbl, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/kubernetes-incubator/metrics-server/pkg/provider"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
apitypes "k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/klog"
|
||||
metrics "k8s.io/metrics/pkg/apis/metrics"
|
||||
|
||||
"github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||
|
|
@ -153,7 +153,7 @@ func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName)
|
|||
resultsByNs := make(map[string]nsQueryResults, len(podsByNs))
|
||||
for result := range resChan {
|
||||
if result.err != nil {
|
||||
glog.Errorf("unable to fetch metrics for pods in namespace %q, skipping: %v", result.namespace, result.err)
|
||||
klog.Errorf("unable to fetch metrics for pods in namespace %q, skipping: %v", result.namespace, result.err)
|
||||
continue
|
||||
}
|
||||
resultsByNs[result.namespace] = result
|
||||
|
|
@ -178,17 +178,17 @@ func (p *resourceProvider) assignForPod(pod apitypes.NamespacedName, resultsByNs
|
|||
// check to make sure everything is present
|
||||
nsRes, nsResPresent := resultsByNs[pod.Namespace]
|
||||
if !nsResPresent {
|
||||
glog.Errorf("unable to fetch metrics for pods in namespace %q, skipping pod %s", pod.Namespace, pod.String())
|
||||
klog.Errorf("unable to fetch metrics for pods in namespace %q, skipping pod %s", pod.Namespace, pod.String())
|
||||
return
|
||||
}
|
||||
cpuRes, hasResult := nsRes.cpu[pod.Name]
|
||||
if !hasResult {
|
||||
glog.Errorf("unable to fetch CPU metrics for pod %s, skipping", pod.String())
|
||||
klog.Errorf("unable to fetch CPU metrics for pod %s, skipping", pod.String())
|
||||
return
|
||||
}
|
||||
memRes, hasResult := nsRes.mem[pod.Name]
|
||||
if !hasResult {
|
||||
glog.Errorf("unable to fetch memory metrics for pod %s, skipping", pod.String())
|
||||
klog.Errorf("unable to fetch memory metrics for pod %s, skipping", pod.String())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -261,12 +261,12 @@ func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]provider.TimeInfo,
|
|||
// skip if any data is missing
|
||||
rawCPUs, gotResult := qRes.cpu[nodeName]
|
||||
if !gotResult {
|
||||
glog.V(1).Infof("missing CPU for node %q, skipping", nodeName)
|
||||
klog.V(1).Infof("missing CPU for node %q, skipping", nodeName)
|
||||
continue
|
||||
}
|
||||
rawMems, gotResult := qRes.mem[nodeName]
|
||||
if !gotResult {
|
||||
glog.V(1).Infof("missing memory for node %q, skipping", nodeName)
|
||||
klog.V(1).Infof("missing memory for node %q, skipping", nodeName)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue