(t *testing.T)
| 308 | } |
| 309 | |
| 310 | func TestLabelsAggregation(t *testing.T) { |
| 311 | t.Parallel() |
| 312 | |
| 313 | type statCollection struct { |
| 314 | labels prometheusmetrics.AgentMetricLabels |
| 315 | metrics []*agentproto.Stats_Metric |
| 316 | } |
| 317 | |
| 318 | commonLabels := []*agentproto.Stats_Metric_Label{ |
| 319 | {Name: agentmetrics.LabelUsername, Value: testUsername}, |
| 320 | {Name: agentmetrics.LabelAgentName, Value: testAgentName}, |
| 321 | {Name: agentmetrics.LabelWorkspaceName, Value: testWorkspaceName}, |
| 322 | {Name: agentmetrics.LabelTemplateName, Value: testTemplateName}, |
| 323 | } |
| 324 | |
| 325 | tests := []struct { |
| 326 | name string |
| 327 | given []statCollection |
| 328 | expected []*agentproto.Stats_Metric |
| 329 | aggregateOn []string |
| 330 | }{ |
| 331 | { |
| 332 | name: "label aggregations not specified, keep all (high cardinality, default behavior)", |
| 333 | aggregateOn: agentmetrics.LabelAll, |
| 334 | given: []statCollection{ |
| 335 | { |
| 336 | labels: testLabels, |
| 337 | metrics: []*agentproto.Stats_Metric{ |
| 338 | {Name: "user_counter", Type: agentproto.Stats_Metric_COUNTER, Value: 1}, |
| 339 | }, |
| 340 | }, |
| 341 | { |
| 342 | labels: testLabels, |
| 343 | metrics: []*agentproto.Stats_Metric{ |
| 344 | {Name: "active_conns", Type: agentproto.Stats_Metric_GAUGE, Value: 4}, |
| 345 | }, |
| 346 | }, |
| 347 | }, |
| 348 | expected: []*agentproto.Stats_Metric{ |
| 349 | {Name: "user_counter", Type: agentproto.Stats_Metric_COUNTER, Value: 1, Labels: commonLabels}, |
| 350 | {Name: "active_conns", Type: agentproto.Stats_Metric_GAUGE, Value: 4, Labels: commonLabels}, |
| 351 | }, |
| 352 | }, |
| 353 | { |
| 354 | // Scenario: 2 users are using the same agent and we've configured the deployment to aggregate on the "agent_name" label. |
| 355 | name: "single label aggregation, aggregating to single metric", |
| 356 | aggregateOn: []string{agentmetrics.LabelAgentName}, |
| 357 | given: []statCollection{ |
| 358 | { |
| 359 | labels: prometheusmetrics.AgentMetricLabels{ |
| 360 | Username: "user1", |
| 361 | AgentName: "agent1", |
| 362 | }, |
| 363 | metrics: []*agentproto.Stats_Metric{ |
| 364 | {Name: "user_counter", Type: agentproto.Stats_Metric_COUNTER, Value: 1}, |
| 365 | }, |
| 366 | }, |
| 367 | { |
nothing calls this directly
no test coverage detected