MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestOTLPConvertToPromTS

Function TestOTLPConvertToPromTS

pkg/util/push/otlp_test.go:359–574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

357}
358
359func 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{

Callers

nothing calls this directly

Calls 6

NewOverridesFunction · 0.92
convertToPromTSFunction · 0.85
MetricsMethod · 0.80
RunMethod · 0.65
EqualMethod · 0.65
AttributesMethod · 0.45

Tested by

no test coverage detected