@@ -31,6 +31,12 @@ import (
31
31
func TestIngester_v2Push (t * testing.T ) {
32
32
metricLabelAdapters := []client.LabelAdapter {{Name : labels .MetricName , Value : "test" }}
33
33
metricLabels := client .FromLabelAdaptersToLabels (metricLabelAdapters )
34
+ metricNames := []string {
35
+ "cortex_ingester_ingested_samples_total" ,
36
+ "cortex_ingester_ingested_samples_failures_total" ,
37
+ "cortex_ingester_memory_series" ,
38
+ "cortex_ingester_memory_users" ,
39
+ }
34
40
userID := "test"
35
41
36
42
tests := map [string ]struct {
@@ -61,6 +67,12 @@ func TestIngester_v2Push(t *testing.T) {
61
67
# HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
62
68
# TYPE cortex_ingester_ingested_samples_failures_total counter
63
69
cortex_ingester_ingested_samples_failures_total 0
70
+ # HELP cortex_ingester_memory_users The current number of users in memory.
71
+ # TYPE cortex_ingester_memory_users gauge
72
+ cortex_ingester_memory_users 1
73
+ # HELP cortex_ingester_memory_series The current number of series in memory.
74
+ # TYPE cortex_ingester_memory_series gauge
75
+ cortex_ingester_memory_series 1
64
76
` ,
65
77
},
66
78
"should soft fail on sample out of order" : {
@@ -85,6 +97,12 @@ func TestIngester_v2Push(t *testing.T) {
85
97
# HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
86
98
# TYPE cortex_ingester_ingested_samples_failures_total counter
87
99
cortex_ingester_ingested_samples_failures_total 1
100
+ # HELP cortex_ingester_memory_users The current number of users in memory.
101
+ # TYPE cortex_ingester_memory_users gauge
102
+ cortex_ingester_memory_users 1
103
+ # HELP cortex_ingester_memory_series The current number of series in memory.
104
+ # TYPE cortex_ingester_memory_series gauge
105
+ cortex_ingester_memory_series 1
88
106
` ,
89
107
},
90
108
"should soft fail on sample out of bound" : {
@@ -109,6 +127,12 @@ func TestIngester_v2Push(t *testing.T) {
109
127
# HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
110
128
# TYPE cortex_ingester_ingested_samples_failures_total counter
111
129
cortex_ingester_ingested_samples_failures_total 1
130
+ # HELP cortex_ingester_memory_users The current number of users in memory.
131
+ # TYPE cortex_ingester_memory_users gauge
132
+ cortex_ingester_memory_users 1
133
+ # HELP cortex_ingester_memory_series The current number of series in memory.
134
+ # TYPE cortex_ingester_memory_series gauge
135
+ cortex_ingester_memory_series 1
112
136
` ,
113
137
},
114
138
"should soft fail on two different sample values at the same timestamp" : {
@@ -133,6 +157,12 @@ func TestIngester_v2Push(t *testing.T) {
133
157
# HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
134
158
# TYPE cortex_ingester_ingested_samples_failures_total counter
135
159
cortex_ingester_ingested_samples_failures_total 1
160
+ # HELP cortex_ingester_memory_users The current number of users in memory.
161
+ # TYPE cortex_ingester_memory_users gauge
162
+ cortex_ingester_memory_users 1
163
+ # HELP cortex_ingester_memory_series The current number of series in memory.
164
+ # TYPE cortex_ingester_memory_series gauge
165
+ cortex_ingester_memory_series 1
136
166
` ,
137
167
},
138
168
}
@@ -182,13 +212,77 @@ func TestIngester_v2Push(t *testing.T) {
182
212
assert .Equal (t , testData .expectedIngested , res .Timeseries )
183
213
184
214
// Check tracked Prometheus metrics
185
- metricNames := []string {"cortex_ingester_ingested_samples_total" , "cortex_ingester_ingested_samples_failures_total" }
186
215
err = testutil .GatherAndCompare (registry , strings .NewReader (testData .expectedMetrics ), metricNames ... )
187
216
assert .NoError (t , err )
188
217
})
189
218
}
190
219
}
191
220
221
+ func TestIngester_v2Push_ShouldCorrectlyTrackMetricsInMultiTenantScenario (t * testing.T ) {
222
+ metricLabelAdapters := []client.LabelAdapter {{Name : labels .MetricName , Value : "test" }}
223
+ metricLabels := client .FromLabelAdaptersToLabels (metricLabelAdapters )
224
+ metricNames := []string {
225
+ "cortex_ingester_ingested_samples_total" ,
226
+ "cortex_ingester_ingested_samples_failures_total" ,
227
+ "cortex_ingester_memory_series" ,
228
+ "cortex_ingester_memory_users" ,
229
+ }
230
+
231
+ registry := prometheus .NewRegistry ()
232
+
233
+ // Create a mocked ingester
234
+ cfg := defaultIngesterTestConfig ()
235
+ cfg .LifecyclerConfig .JoinAfter = 0
236
+
237
+ i , cleanup , err := newIngesterMockWithTSDBStorage (cfg , registry )
238
+ require .NoError (t , err )
239
+ defer i .Shutdown ()
240
+ defer cleanup ()
241
+
242
+ // Wait until the ingester is ACTIVE
243
+ test .Poll (t , 100 * time .Millisecond , ring .ACTIVE , func () interface {} {
244
+ return i .lifecycler .GetState ()
245
+ })
246
+
247
+ // Push timeseries for each user
248
+ for _ , userID := range []string {"test-1" , "test-2" } {
249
+ reqs := []* client.WriteRequest {
250
+ client .ToWriteRequest (
251
+ []labels.Labels {metricLabels },
252
+ []client.Sample {{Value : 1 , TimestampMs : 9 }},
253
+ client .API ),
254
+ client .ToWriteRequest (
255
+ []labels.Labels {metricLabels },
256
+ []client.Sample {{Value : 2 , TimestampMs : 10 }},
257
+ client .API ),
258
+ }
259
+
260
+ for _ , req := range reqs {
261
+ ctx := user .InjectOrgID (context .Background (), userID )
262
+ _ , err := i .v2Push (ctx , req )
263
+ require .NoError (t , err )
264
+ }
265
+ }
266
+
267
+ // Check tracked Prometheus metrics
268
+ expectedMetrics := `
269
+ # HELP cortex_ingester_ingested_samples_total The total number of samples ingested.
270
+ # TYPE cortex_ingester_ingested_samples_total counter
271
+ cortex_ingester_ingested_samples_total 4
272
+ # HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
273
+ # TYPE cortex_ingester_ingested_samples_failures_total counter
274
+ cortex_ingester_ingested_samples_failures_total 0
275
+ # HELP cortex_ingester_memory_users The current number of users in memory.
276
+ # TYPE cortex_ingester_memory_users gauge
277
+ cortex_ingester_memory_users 2
278
+ # HELP cortex_ingester_memory_series The current number of series in memory.
279
+ # TYPE cortex_ingester_memory_series gauge
280
+ cortex_ingester_memory_series 2
281
+ `
282
+
283
+ assert .NoError (t , testutil .GatherAndCompare (registry , strings .NewReader (expectedMetrics ), metricNames ... ))
284
+ }
285
+
192
286
func Test_Ingester_v2LabelNames (t * testing.T ) {
193
287
series := []struct {
194
288
lbls labels.Labels
0 commit comments