From c79792313228247aa038c60796b8d0948cdc37d0 Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Fri, 5 Jan 2018 21:18:23 +0800 Subject: [PATCH] revert componentstatus --- Documentation/README.md | 1 - Documentation/componentstatus-metrics.md | 5 -- collectors/componentstatus.go | 106 ----------------------- collectors/componentstatus_test.go | 83 ------------------ main.go | 2 - 5 files changed, 197 deletions(-) delete mode 100644 Documentation/componentstatus-metrics.md delete mode 100644 collectors/componentstatus.go delete mode 100644 collectors/componentstatus_test.go diff --git a/Documentation/README.md b/Documentation/README.md index fbf2cdcc..95f3f5d8 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -6,7 +6,6 @@ Any contribution to improving this documentation or adding sample usages will be Per group of metrics there is one file for each metrics. See each file for specific documentation about the exposed metrics: -* [ComponentStatus Metrics](componentstatus-metrics.md) * [CronJob Metrics](cronjob-metrics.md) * [DaemonSet Metrics](daemonset-metrics.md) * [Deployment Metrics](deployment-metrics.md) diff --git a/Documentation/componentstatus-metrics.md b/Documentation/componentstatus-metrics.md deleted file mode 100644 index 90f18e65..00000000 --- a/Documentation/componentstatus-metrics.md +++ /dev/null @@ -1,5 +0,0 @@ -# Service Metrics - -| Metric name| Metric type | Labels/tags | -| ---------- | ----------- | ----------- | -| kube_componentstatus_status_healthy | Gauge | `name`=<component-name>
`status`=<True\|False\|Unknow> | diff --git a/collectors/componentstatus.go b/collectors/componentstatus.go deleted file mode 100644 index 216b1330..00000000 --- a/collectors/componentstatus.go +++ /dev/null @@ -1,106 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package collectors - -import ( - "github.com/golang/glog" - "github.com/prometheus/client_golang/prometheus" - "golang.org/x/net/context" - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/cache" -) - -var ( - descComponentStatusStatusHealthy = prometheus.NewDesc( - "kube_componentstatus_status_healthy", - "kube component status healthy status.", - []string{"name", "status"}, nil, - ) -) - -type ComponentStatusLister func() (v1.ComponentStatusList, error) - -func (csl ComponentStatusLister) List() (v1.ComponentStatusList, error) { - return csl() -} - -func RegisterComponentStatusCollector(registry prometheus.Registerer, kubeClient kubernetes.Interface, namespace string) { - client := kubeClient.CoreV1().RESTClient() - glog.Infof("collect componentstatuses with %s", client.APIVersion()) - slw := cache.NewListWatchFromClient(client, "componentstatuses", v1.NamespaceAll, fields.Everything()) - sinf := cache.NewSharedInformer(slw, &v1.ComponentStatus{}, resyncPeriod) - - componentStatusLister := ComponentStatusLister(func() (componentStatuses v1.ComponentStatusList, err error) { - for _, m := range sinf.GetStore().List() { - componentStatuses.Items = append(componentStatuses.Items, *m.(*v1.ComponentStatus)) - } - return componentStatuses, nil - }) - - registry.MustRegister(&componentStatusCollector{store: componentStatusLister}) - go sinf.Run(context.Background().Done()) -} - -type componentStatusStore interface { - List() (componentStatuses v1.ComponentStatusList, err error) -} - -// componentStatusCollector collects metrics about all components in the cluster. -type componentStatusCollector struct { - store componentStatusStore -} - -// Describe implements the prometheus.Collector interface. -func (csc *componentStatusCollector) Describe(ch chan<- *prometheus.Desc) { - ch <- descComponentStatusStatusHealthy -} - -// Collect implements the prometheus.Collector interface. -func (csc *componentStatusCollector) Collect(ch chan<- prometheus.Metric) { - csl, err := csc.store.List() - if err != nil { - ScrapeErrorTotalMetric.With(prometheus.Labels{"resource": "componentstatus"}).Inc() - glog.Errorf("listing component status failed: %s", err) - return - } - - ResourcesPerScrapeMetric.With(prometheus.Labels{"resource": "componentstatus"}).Observe(float64(len(csl.Items))) - for _, s := range csl.Items { - csc.collectComponentStatus(ch, s) - } - glog.Infof("collected %d componentstatuses", len(csl.Items)) -} - -func (csc *componentStatusCollector) collectComponentStatus(ch chan<- prometheus.Metric, s v1.ComponentStatus) { - addConstMetric := func(desc *prometheus.Desc, t prometheus.ValueType, v float64, lv ...string) { - lv = append([]string{s.Name}, lv...) - ch <- prometheus.MustNewConstMetric(desc, t, v, lv...) - } - addGauge := func(desc *prometheus.Desc, v float64, lv ...string) { - addConstMetric(desc, prometheus.GaugeValue, v, lv...) - } - for _, p := range s.Conditions { - if p.Type == v1.ComponentHealthy { - addGauge(descComponentStatusStatusHealthy, boolFloat64(p.Status == v1.ConditionTrue), string(v1.ConditionTrue)) - addGauge(descComponentStatusStatusHealthy, boolFloat64(p.Status == v1.ConditionFalse), string(v1.ConditionFalse)) - addGauge(descComponentStatusStatusHealthy, boolFloat64(p.Status == v1.ConditionUnknown), string(v1.ConditionUnknown)) - break - } - } -} diff --git a/collectors/componentstatus_test.go b/collectors/componentstatus_test.go deleted file mode 100644 index e5dc36f1..00000000 --- a/collectors/componentstatus_test.go +++ /dev/null @@ -1,83 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package collectors - -import ( - "testing" - - "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type mockcomponentStatusStore struct { - list func() (v1.ComponentStatusList, error) -} - -func (mcs mockcomponentStatusStore) List() (v1.ComponentStatusList, error) { - return mcs.list() -} - -func TestComponentStatusCollector(t *testing.T) { - // Fixed metadata on type and help text. We prepend this to every expected - // output so we only have to modify a single place when doing adjustments. - const metadata = ` - # HELP kube_componentstatus_status_healthy kube component status healthy status. - # TYPE kube_componentstatus_status_healthy gauge - ` - cases := []struct { - cms v1.ComponentStatusList - metrics []string // which metrics should be checked - want string - }{ - // Verify phase enumerations. - { - cms: v1.ComponentStatusList{ - Items: []v1.ComponentStatus{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "etcd1", - }, - Conditions: []v1.ComponentCondition{ - { - Type: v1.ComponentHealthy, - Status: v1.ConditionTrue, - }, - }, - }, - }, - }, - want: metadata + ` - kube_componentstatus_status_healthy{name="etcd1",status="False"} 0 - kube_componentstatus_status_healthy{name="etcd1",status="True"} 1 - kube_componentstatus_status_healthy{name="etcd1",status="Unknown"} 0 - `, - metrics: []string{"kube_componentstatus_status_healthy"}, - }, - } - for _, c := range cases { - dc := &componentStatusCollector{ - store: &mockcomponentStatusStore{ - list: func() (v1.ComponentStatusList, error) { - return c.cms, nil - }, - }, - } - if err := gatherAndCompare(dc, c.want, c.metrics); err != nil { - t.Errorf("unexpected collecting result:\n%s", err) - } - } -} diff --git a/main.go b/main.go index b7ec42b3..69238e7d 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,6 @@ const ( var ( defaultCollectors = collectorSet{ - "componentstatuses": struct{}{}, "daemonsets": struct{}{}, "deployments": struct{}{}, "limitranges": struct{}{}, @@ -69,7 +68,6 @@ var ( "endpoints": struct{}{}, } availableCollectors = map[string]func(registry prometheus.Registerer, kubeClient clientset.Interface, namespace string){ - "componentstatuses": kcollectors.RegisterComponentStatusCollector, "cronjobs": kcollectors.RegisterCronJobCollector, "daemonsets": kcollectors.RegisterDaemonSetCollector, "deployments": kcollectors.RegisterDeploymentCollector,