Skip to content

Unexpected behavior of Collect for curried vector #1700

@palage4a

Description

@palage4a

Hi there. I am expecting that after currying a metric vector, i would able to collect metrics only for curried version of vector.
Here is representation of my expectations in test.

Library version: v1.19.0.

func TestMustCurryWithCollect(t *testing.T) {
	req := prometheus.NewRegistry()

	c := promauto.With(req).NewCounterVec(prometheus.CounterOpts{
		Name: "counter_total",
		Help: "help",
	}, []string{"success"})

	expectedFailed := float64(5)
	expectedSuccessed := float64(10)

	c.WithLabelValues("false").Add(expectedFailed)
	c.WithLabelValues("true").Add(expectedSuccessed)

	failedCh := make(chan prometheus.Metric)
	go func() {
		c.MustCurryWith(prometheus.Labels{"success": "false"}).Collect(failedCh)
		close(failedCh)
	}()

	successedCh := make(chan prometheus.Metric)
	go func() {
		c.MustCurryWith(prometheus.Labels{"success": "true"}).Collect(successedCh)
		close(successedCh)
	}()

	s := float64(0)
	f := float64(0)

	for metric := range failedCh {
		var m dto.Metric
		err := metric.Write(&m)
		assert.Nil(t, err)
		f += m.GetCounter().GetValue()
	}

	for metric := range successedCh {
		var m dto.Metric
		err := metric.Write(&m)
		assert.Nil(t, err)
		s += m.GetCounter().GetValue()
	}

	assert.Equal(t, expectedSuccessed, s)
	assert.Equal(t, expectedFailed, f)
}

Mb i am trying the wrong stuff in the first place? My general goal - get count of successed/failed requests independently to response code (i deleted "code" label for in favor of test example).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions