(t *testing.T)
| 357 | } |
| 358 | |
| 359 | func TestOTLPConvertToPromTS(t *testing.T) { |
| 360 | logger := log.NewNopLogger() |
| 361 | ctx := context.Background() |
| 362 | d := pmetric.NewMetrics() |
| 363 | resourceMetric := d.ResourceMetrics().AppendEmpty() |
| 364 | resourceMetric.Resource().Attributes().PutStr("service.name", "test-service") // converted to job, service_name |
| 365 | resourceMetric.Resource().Attributes().PutStr("attr1", "value") |
| 366 | resourceMetric.Resource().Attributes().PutStr("attr2", "value") |
| 367 | resourceMetric.Resource().Attributes().PutStr("attr3", "value") |
| 368 | |
| 369 | scopeMetric := resourceMetric.ScopeMetrics().AppendEmpty() |
| 370 | |
| 371 | //Generate One Counter |
| 372 | timestamp := time.Now() |
| 373 | counterMetric := scopeMetric.Metrics().AppendEmpty() |
| 374 | counterMetric.SetName("test-counter") |
| 375 | counterMetric.SetDescription("test-counter-description") |
| 376 | counterMetric.SetEmptySum() |
| 377 | counterMetric.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) |
| 378 | counterMetric.Sum().SetIsMonotonic(true) |
| 379 | |
| 380 | counterDataPoint := counterMetric.Sum().DataPoints().AppendEmpty() |
| 381 | counterDataPoint.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) |
| 382 | counterDataPoint.SetDoubleValue(10.0) |
| 383 | |
| 384 | tests := []struct { |
| 385 | description string |
| 386 | PromoteResourceAttributes []string |
| 387 | cfg distributor.OTLPConfig |
| 388 | expectedLabels []prompb.Label |
| 389 | }{ |
| 390 | { |
| 391 | description: "target_info should be generated and an attribute that exist in promote resource attributes should be converted", |
| 392 | PromoteResourceAttributes: []string{"attr1"}, |
| 393 | cfg: distributor.OTLPConfig{ |
| 394 | ConvertAllAttributes: false, |
| 395 | DisableTargetInfo: false, |
| 396 | AddMetricSuffixes: true, |
| 397 | }, |
| 398 | expectedLabels: []prompb.Label{ |
| 399 | { |
| 400 | Name: "__name__", |
| 401 | Value: "test_counter_total", |
| 402 | }, |
| 403 | { |
| 404 | Name: "attr1", |
| 405 | Value: "value", |
| 406 | }, |
| 407 | { |
| 408 | Name: "job", |
| 409 | Value: "test-service", |
| 410 | }, |
| 411 | }, |
| 412 | }, |
| 413 | { |
| 414 | description: "an attributes that exist in promote resource attributes should be converted", |
| 415 | PromoteResourceAttributes: []string{"attr1"}, |
| 416 | cfg: distributor.OTLPConfig{ |
nothing calls this directly
no test coverage detected