Skip to content

How to clean self-data metric?  #5917

Open
@rockingl

Description

@rockingl

Hi,
First of all, thank you for your excellent work.
Recently, I encountered some problems while doing push notifications for monitoring. Here is my code.

         // create http oltp exporter,exporter private data(similar to promethus collector.textfile.directory),not Datapoint
        exporter, _ := otlpmetrichttp.New(ctx, otlpmetrichttp.WithInsecure(), otlpmetrichttp.WithEndpoint(endpoint),
		otlpmetrichttp.WithURLPath(urlpath))

        // create provider
	meterProvider := metric.NewMeterProvider(metric.WithReader(metric.NewPeriodicReader(exporter, metric.WithInterval(15*time.Second))))
	otel.SetMeterProvider(meterProvider)

        // create meter
	meter := otel.GetMeterProvider().Meter("test_metric")
	
        // promethus: tag -> value
        // Notice:private data(has existed), not Datapoint
        opt1 := api.WithAttributes(
	      attribute.Key("a").String("b"),
	      attribute.Key("c").String("d"),
	)
        opt2 := api.WithAttributes(
	      attribute.Key("a").String("b"),
	      attribute.Key("c").String("e"), // value is changed
	)
        // create gauge metric name
	gauge,_ := meter.Float64Gauge("test_float64gauage", api.WithDescription("a fun little gauge"))

        // exporter data 
	cnt := 1.0
	for i := 0; i < 2; i++{
		time.Sleep(15 * time.Second)
		cnt++
		gauge.Record(context.Background(), cnt, opt1)
	}

        // end,i hope this attribute disappear, because it's not on the record

	cnt = 10.0
        for i := 0; i < 2; i++ {
		time.Sleep(15 * time.Second)
		cnt++
		gauge.Record(context.Background(), cnt, opt2)
	} 
        //  use the new attribute instead

My goal is to keep only the latest data, but this is not the case. However, two data appear, and the value of the first data has not changed. Is there a cleanup/update mechanism that can clean up the attribute data? Or is my approach wrong and there is another approach that is more suitable for this scenario? Any help would be appreciated,thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked:specificationWaiting on clarification of the OpenTelemetry specification before progress can be madeenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions