Skip to content

Commit 7ffa823

Browse files
committed
rename cluster to consumer
Signed-off-by: clyang82 <chuyang@redhat.com>
1 parent 02daddd commit 7ffa823

2 files changed

Lines changed: 47 additions & 39 deletions

File tree

pkg/cloudevents/generic/metrics_collector.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
const (
1818
metricsSourceLabel = "source"
1919
metricsOriginalSourceLabel = "original_source"
20+
metricsConsumerLabel = "consumer"
2021
metricsDataTypeLabel = "type"
2122
metricsSubResourceLabel = "subresource"
2223
metricsActionLabel = "action"
@@ -30,6 +31,7 @@ const noneOriginalSource = "none"
3031
// cloudeventsReceivedMetricsLabels - Array of labels added to cloudevents received metrics:
3132
var cloudeventsReceivedMetricsLabels = []string{
3233
metricsSourceLabel, // source
34+
metricsConsumerLabel, // consumer
3335
metricsDataTypeLabel, // data type, e.g. manifests, manifestbundles
3436
metricsSubResourceLabel, // subresource, eg, spec or status
3537
metricsActionLabel, // action, eg, create, update, delete, resync_request, resync_response
@@ -39,6 +41,7 @@ var cloudeventsReceivedMetricsLabels = []string{
3941
var cloudeventsSentMetricsLabels = []string{
4042
metricsSourceLabel, // source
4143
metricsOriginalSourceLabel, // original source, if no, set to "none"
44+
metricsConsumerLabel, // consumer
4245
metricsDataTypeLabel, // data type, e.g. manifests, manifestbundles
4346
metricsSubResourceLabel, // subresource, eg, spec or status
4447
metricsActionLabel, // action, eg, create, update, delete, resync_request, resync_response
@@ -47,6 +50,7 @@ var cloudeventsSentMetricsLabels = []string{
4750
// cloudeventsResyncMetricsLabels - Array of labels added to cloudevents resync metrics:
4851
var cloudeventsResyncMetricsLabels = []string{
4952
metricsSourceLabel, // source
53+
metricsConsumerLabel, // consumer
5054
metricsDataTypeLabel, // data type, e.g. manifests, manifestbundles
5155
}
5256

@@ -73,10 +77,10 @@ const (
7377

7478
// The cloudevents received counter metric is a counter with a base metric name of 'received_total'
7579
// and a help string of 'The total number of received CloudEvents.'
76-
// For example, 2 CloudEvents received from source1 to agent with data type manifests, one for resource create,
80+
// For example, 2 CloudEvents received from source1 to consumer1 with data type manifests, one for resource create,
7781
// another for resource update would result in the following metrics:
78-
// cloudevents_received_total{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",subresource="spec",action="create"} 1
79-
// cloudevents_received_total{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",subresource="spec",action="update"} 1
82+
// cloudevents_received_total{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",subresource="spec",action="create"} 1
83+
// cloudevents_received_total{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",subresource="spec",action="update"} 1
8084
var cloudeventsReceivedCounterMetric = prometheus.NewCounterVec(
8185
prometheus.CounterOpts{
8286
Subsystem: cloudeventsMetricsSubsystem,
@@ -89,9 +93,9 @@ var cloudeventsReceivedCounterMetric = prometheus.NewCounterVec(
8993
// The cloudevents sent counter metric is a counter with a base metric name of 'sent_total'
9094
// and a help string of 'The total number of sent CloudEvents.'
9195
// For example, 1 cloudevent sent from source1 with data type manifestbundles for resource spec create (original source is empty),
92-
// and 2 CloudEvents sent from agent back to source1 for resource status update would result in the following metrics:
93-
// cloudevents_sent_total{source="source1",original_source="none",type="io.open-cluster-management.works.v1alpha1.manifestbundles",subresource="spec",action="create"} 1
94-
// cloudevents_sent_total{source="cluster1-work-agent",original_source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",subresource="status",action="update"} 2
96+
// and 2 CloudEvents sent from consumer1-work-agent back to source1 for resource status update would result in the following metrics:
97+
// cloudevents_sent_total{source="source1",original_source="none",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",subresource="spec",action="create"} 1
98+
// cloudevents_sent_total{source="consumer1-work-agent",original_source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",subresource="status",action="update"} 2
9599
var cloudeventsSentCounterMetric = prometheus.NewCounterVec(
96100
prometheus.CounterOpts{
97101
Subsystem: cloudeventsMetricsSubsystem,
@@ -107,16 +111,16 @@ var cloudeventsSentCounterMetric = prometheus.NewCounterVec(
107111
// 2. the total sum of all observed values, exposed as 'resource_spec_resync_duration_seconds_sum'
108112
// 3. the count of events that have been observed, exposed as 'resource_spec_resync_duration_seconds_count' (identical to 'resource_spec_resync_duration_seconds_bucket{le="+Inf"}' above)
109113
// For example, 2 resource spec resync for manifests type that have been observed, one taking 0.5s and the other taking 0.7s, would result in the following metrics:
110-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.1"} 0
111-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.2"} 0
112-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.5"} 1
113-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="1.0"} 2
114-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="2.0"} 2
115-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="10.0"} 2
116-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="30.0"} 2
117-
// resource_spec_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests",le="+Inf"} 2
118-
// resource_spec_resync_duration_seconds_sum{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests"} 1.2
119-
// resource_spec_resync_duration_seconds_count{source="source1",type="io.open-cluster-management.works.v1alpha1.manifests"} 2
114+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.1"} 0
115+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.2"} 0
116+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="0.5"} 1
117+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="1.0"} 2
118+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="2.0"} 2
119+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="10.0"} 2
120+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="30.0"} 2
121+
// resource_spec_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests",le="+Inf"} 2
122+
// resource_spec_resync_duration_seconds_sum{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests"} 1.2
123+
// resource_spec_resync_duration_seconds_count{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifests"} 2
120124
var resourceSpecResyncDurationMetric = prometheus.NewHistogramVec(
121125
prometheus.HistogramOpts{
122126
Subsystem: resourcesMetricsSubsystem,
@@ -141,16 +145,16 @@ var resourceSpecResyncDurationMetric = prometheus.NewHistogramVec(
141145
// 2. the total sum of all observed values, exposed as 'resource_status_resync_duration_seconds_sum'
142146
// 3. the count of events that have been observed, exposed as 'resource_status_resync_duration_seconds_count' (identical to 'resource_status_resync_duration_seconds_bucket{le="+Inf"}' above)
143147
// For example, 2 resource status resync for manifestbundles type that have been observed, one taking 0.5s and the other taking 1.1s, would result in the following metrics:
144-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.1"} 0
145-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.2"} 0
146-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.5"} 1
147-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="1.0"} 1
148-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="2.0"} 2
149-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="10.0"} 2
150-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="30.0"} 2
151-
// resource_status_resync_duration_seconds_bucket{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="+Inf"} 2
152-
// resource_status_resync_duration_seconds_sum{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles"} 1.6
153-
// resource_status_resync_duration_seconds_count{source="source1",type="io.open-cluster-management.works.v1alpha1.manifestbundles"} 2
148+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.1"} 0
149+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.2"} 0
150+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="0.5"} 1
151+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="1.0"} 1
152+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="2.0"} 2
153+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="10.0"} 2
154+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="30.0"} 2
155+
// resource_status_resync_duration_seconds_bucket{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles",le="+Inf"} 2
156+
// resource_status_resync_duration_seconds_sum{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles"} 1.6
157+
// resource_status_resync_duration_seconds_count{source="source1",consumer="consumer1",type="io.open-cluster-management.works.v1alpha1.manifestbundles"} 2
154158
var resourceStatusResyncDurationMetric = prometheus.NewHistogramVec(
155159
prometheus.HistogramOpts{
156160
Subsystem: resourcesMetricsSubsystem,
@@ -221,10 +225,11 @@ func ResetCloudEventsMetrics() {
221225
workProcessedCounterMetric.Reset()
222226
}
223227

224-
// increaseCloudEventsReceivedCounter increases the cloudevents sent counter metric:
225-
func increaseCloudEventsReceivedCounter(source, cluster, dataType, subresource, action string) {
228+
// increaseCloudEventsReceivedCounter increases the cloudevents received counter metric:
229+
func increaseCloudEventsReceivedCounter(source, consumer, dataType, subresource, action string) {
226230
labels := prometheus.Labels{
227231
metricsSourceLabel: source,
232+
metricsConsumerLabel: consumer,
228233
metricsDataTypeLabel: dataType,
229234
metricsSubResourceLabel: subresource,
230235
metricsActionLabel: action,
@@ -233,13 +238,14 @@ func increaseCloudEventsReceivedCounter(source, cluster, dataType, subresource,
233238
}
234239

235240
// increaseCloudEventsSentCounter increases the cloudevents sent counter metric:
236-
func increaseCloudEventsSentCounter(source, originalSource, cluster, dataType, subresource, action string) {
241+
func increaseCloudEventsSentCounter(source, originalSource, consumer, dataType, subresource, action string) {
237242
if originalSource == "" {
238243
originalSource = noneOriginalSource
239244
}
240245
labels := prometheus.Labels{
241246
metricsSourceLabel: source,
242247
metricsOriginalSourceLabel: originalSource,
248+
metricsConsumerLabel: consumer,
243249
metricsDataTypeLabel: dataType,
244250
metricsSubResourceLabel: subresource,
245251
metricsActionLabel: action,
@@ -248,19 +254,21 @@ func increaseCloudEventsSentCounter(source, originalSource, cluster, dataType, s
248254
}
249255

250256
// updateResourceSpecResyncDurationMetric updates the resource spec resync duration metric:
251-
func updateResourceSpecResyncDurationMetric(source, cluster, dataType string, startTime time.Time) {
257+
func updateResourceSpecResyncDurationMetric(source, consumer, dataType string, startTime time.Time) {
252258
labels := prometheus.Labels{
253259
metricsSourceLabel: source,
260+
metricsConsumerLabel: consumer,
254261
metricsDataTypeLabel: dataType,
255262
}
256263
duration := time.Since(startTime)
257264
resourceSpecResyncDurationMetric.With(labels).Observe(duration.Seconds())
258265
}
259266

260267
// updateResourceStatusResyncDurationMetric updates the resource status resync duration metric:
261-
func updateResourceStatusResyncDurationMetric(source, cluster, dataType string, startTime time.Time) {
268+
func updateResourceStatusResyncDurationMetric(source, consumer, dataType string, startTime time.Time) {
262269
labels := prometheus.Labels{
263270
metricsSourceLabel: source,
271+
metricsConsumerLabel: consumer,
264272
metricsDataTypeLabel: dataType,
265273
}
266274
duration := time.Since(startTime)

pkg/cloudevents/generic/metrics_collector_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func TestCloudEventsMetrics(t *testing.T) {
9999
time.Sleep(time.Second)
100100

101101
// ensure metrics are updated
102-
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(c.sourceID, noneOriginalSource, c.dataType.String(), string(c.subresource), string(c.action))
102+
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(c.sourceID, noneOriginalSource, c.clusterName, c.dataType.String(), string(c.subresource), string(c.action))
103103
require.Equal(t, len(c.resources), int(toFloat64Counter(sentTotal)))
104-
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.sourceID, c.dataType.String(), string(c.subresource), string(c.action))
104+
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.sourceID, c.clusterName, c.dataType.String(), string(c.subresource), string(c.action))
105105
require.Equal(t, len(c.resources), int(toFloat64Counter(receivedTotal)))
106106

107107
cancel()
@@ -235,20 +235,20 @@ func TestResyncMetrics(t *testing.T) {
235235
// receive resync request and publish associated resources
236236
source.receive(ctx, evt)
237237

238-
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.clusterName, c.dataType.String(), string(types.SubResourceSpec), string(types.ResyncRequestAction))
238+
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.clusterName, c.clusterName, c.dataType.String(), string(types.SubResourceSpec), string(types.ResyncRequestAction))
239239
require.Equal(t, 1, int(toFloat64Counter(receivedTotal)))
240240

241241
// wait 1 seconds to respond to the spec resync request
242242
time.Sleep(1 * time.Second)
243243

244244
// check spec resync duration metric as a histogram
245-
h := resourceSpecResyncDurationMetric.WithLabelValues(c.sourceID, c.dataType.String())
245+
h := resourceSpecResyncDurationMetric.WithLabelValues(c.sourceID, c.clusterName, c.dataType.String())
246246
count, sum := toFloat64HistCountAndSum(h)
247247
require.Equal(t, uint64(1), count)
248248
require.Greater(t, sum, 0.0)
249249
require.Less(t, sum, 1.0)
250250

251-
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(c.sourceID, noneOriginalSource, c.dataType.String(), string(types.SubResourceSpec), string(types.ResyncResponseAction))
251+
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(c.sourceID, noneOriginalSource, c.clusterName, c.dataType.String(), string(types.SubResourceSpec), string(types.ResyncResponseAction))
252252
require.Equal(t, len(c.resources), int(toFloat64Counter(sentTotal)))
253253
}
254254

@@ -274,20 +274,20 @@ func TestResyncMetrics(t *testing.T) {
274274
// receive resync request and publish associated resources
275275
agent.receive(ctx, evt)
276276

277-
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.sourceID, c.dataType.String(), string(types.SubResourceStatus), string(types.ResyncRequestAction))
277+
receivedTotal := cloudeventsReceivedCounterMetric.WithLabelValues(c.sourceID, c.clusterName, c.dataType.String(), string(types.SubResourceStatus), string(types.ResyncRequestAction))
278278
require.Equal(t, 1, int(toFloat64Counter(receivedTotal)))
279279

280280
// wait 1 seconds to respond to the resync request
281281
time.Sleep(1 * time.Second)
282282

283283
// check status resync duration metric as a histogram
284-
h := resourceStatusResyncDurationMetric.WithLabelValues(c.sourceID, c.dataType.String())
284+
h := resourceStatusResyncDurationMetric.WithLabelValues(c.sourceID, c.clusterName, c.dataType.String())
285285
count, sum := toFloat64HistCountAndSum(h)
286286
require.Equal(t, uint64(1), count)
287287
require.Greater(t, sum, 0.0)
288288
require.Less(t, sum, 1.0)
289289

290-
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(testAgentName, noneOriginalSource, c.dataType.String(), string(types.SubResourceStatus), string(types.ResyncResponseAction))
290+
sentTotal := cloudeventsSentCounterMetric.WithLabelValues(testAgentName, noneOriginalSource, c.clusterName, c.dataType.String(), string(types.SubResourceStatus), string(types.ResyncResponseAction))
291291
require.Equal(t, len(c.resources), int(toFloat64Counter(sentTotal)))
292292
}
293293

0 commit comments

Comments
 (0)