Skip to content

Commit

Permalink
Merge pull request #54921 from weiwei04/fix_reflector_last_resource_v…
Browse files Browse the repository at this point in the history
…ersion

Automatic merge from submit-queue (batch tested with PRs 54800, 53898, 54812, 54921, 53558). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

rename metric reflector_xx_last_resource_version

**What this PR does / why we need it**:

mv reflector name from metric name to metric label

before:

```
reflector_k8s_io_kubernetes_pkg_client_informers_informers_generated_internalversion_factory_go:73_8664_last_resource_version{instance="104.154.20.21:443",job="kubernetes-apiservers"}
```

after

```
reflector_last_resource_version{instance="10.0.2.15:6443",job="kubernetes-apiservers",name="k8s_io_kubernetes_pkg_client_informers_informers_generated_internalversion_factory_go_73_8664"}
```

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #52121 

**Special notes for your reviewer**:

None

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Nov 2, 2017
2 parents e989ca4 + bca495e commit b7968e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions pkg/util/reflector/prometheus/prometheus.go
Expand Up @@ -68,6 +68,12 @@ var (
Name: "items_per_watch",
Help: "How many items an API watch returns to the reflectors",
}, []string{"name"})

lastResourceVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: reflectorSubsystem,
Name: "last_resource_version",
Help: "Last resource version seen for the reflectors",
}, []string{"name"})
)

func init() {
Expand All @@ -78,6 +84,7 @@ func init() {
prometheus.MustRegister(shortWatchesTotal)
prometheus.MustRegister(watchDuration)
prometheus.MustRegister(itemsPerWatch)
prometheus.MustRegister(lastResourceVersion)

cache.SetReflectorMetricsProvider(prometheusMetricsProvider{})
}
Expand Down Expand Up @@ -117,11 +124,5 @@ func (prometheusMetricsProvider) NewItemsInWatchMetric(name string) cache.Summar
}

func (prometheusMetricsProvider) NewLastResourceVersionMetric(name string) cache.GaugeMetric {
rv := prometheus.NewGauge(prometheus.GaugeOpts{
Subsystem: name,
Name: "last_resource_version",
Help: "last resource version seen for the reflectors",
})
prometheus.MustRegister(rv)
return rv
return lastResourceVersion.WithLabelValues(name)
}
6 changes: 3 additions & 3 deletions staging/src/k8s.io/client-go/tools/cache/reflector.go
Expand Up @@ -109,7 +109,7 @@ func NewNamedReflector(name string, lw ListerWatcher, expectedType interface{},
r := &Reflector{
name: name,
// we need this to be unique per process (some names are still the same)but obvious who it belongs to
metrics: newReflectorMetrics(makeValidPromethusMetricName(fmt.Sprintf("reflector_"+name+"_%d", reflectorSuffix))),
metrics: newReflectorMetrics(makeValidPromethusMetricLabel(fmt.Sprintf("reflector_"+name+"_%d", reflectorSuffix))),
listerWatcher: lw,
store: store,
expectedType: reflect.TypeOf(expectedType),
Expand All @@ -120,9 +120,9 @@ func NewNamedReflector(name string, lw ListerWatcher, expectedType interface{},
return r
}

func makeValidPromethusMetricName(in string) string {
func makeValidPromethusMetricLabel(in string) string {
// this isn't perfect, but it removes our common characters
return strings.NewReplacer("/", "_", ".", "_", "-", "_").Replace(in)
return strings.NewReplacer("/", "_", ".", "_", "-", "_", ":", "_").Replace(in)
}

// internalPackages are packages that ignored when creating a default reflector name. These packages are in the common
Expand Down

0 comments on commit b7968e0

Please sign in to comment.