Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Gauge negative values not working #1250

Open
@Michaelhobo

Description

@Michaelhobo

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.22.5

What version of Go are you using?

1.14

What did you do?

If possible, provide a recipe for reproducing the error.

I'm writing a wrapper library for opencensus. While writing tests, I noticed that gauges don't seem to handle negative values. You can reproduce this here:
https://play.golang.org/p/y2skt697rOc

What did you expect to see?

The Float/Int64Gauge tests that go negative fail. When the gauge stays positive, the tests pass.

What did you see instead?

It seems like any negative value causes the gauge to go to 0.

Here's the test output, in case the playground doesn't compile later:

=== RUN   TestMetrics
=== RUN   TestMetrics/Float64Gauge_negative
    prog.go:120: Registry.Read() (-want +got):
          []*metricdata.Metric{
          	&{
          		Descriptor: {Name: "bye_gauge", Type: s"TypeGaugeFloat64"},
          		Resource:   nil,
          		TimeSeries: []*metricdata.TimeSeries{
          			&{
          				LabelValues: {},
          				Points: []metricdata.Point{
          					{
          						... // 1 ignored field
        - 						Value: float64(-2.8),
        + 						Value: float64(0),
          					},
          				},
          				... // 1 ignored field
          			},
          		},
          	},
          }
=== RUN   TestMetrics/Int64Cumulative
=== RUN   TestMetrics/Int64Gauge_add_from_nothing
=== RUN   TestMetrics/Int64Gauge_set_then_add
=== RUN   TestMetrics/Int64Gauge_negative
    prog.go:120: Registry.Read() (-want +got):
          []*metricdata.Metric{
          	&{
          		Descriptor: {Name: "hello_gauge"},
          		Resource:   nil,
          		TimeSeries: []*metricdata.TimeSeries{
          			&{
          				LabelValues: {},
          				Points: []metricdata.Point{
          					{
          						... // 1 ignored field
        - 						Value: int64(-50),
        + 						Value: int64(0),
          					},
          				},
          				... // 1 ignored field
          			},
          		},
          	},
          }
=== RUN   TestMetrics/Float64Cumulative
=== RUN   TestMetrics/Float64Gauge
--- FAIL: TestMetrics (0.00s)
    --- FAIL: TestMetrics/Float64Gauge_negative (0.00s)
    --- PASS: TestMetrics/Int64Cumulative (0.00s)
    --- PASS: TestMetrics/Int64Gauge_add_from_nothing (0.00s)
    --- PASS: TestMetrics/Int64Gauge_set_then_add (0.00s)
    --- FAIL: TestMetrics/Int64Gauge_negative (0.00s)
    --- PASS: TestMetrics/Float64Cumulative (0.00s)
    --- PASS: TestMetrics/Float64Gauge (0.00s)
FAIL

3 tests failed.

Additional context

Add any other context about the problem here.

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