Hi -- kinda random question. I have an UpDownCounter that I'd like to add to my dashboard. In the ...
d
Hi -- kinda random question. I have an UpDownCounter that I'd like to add to my dashboard. In the app it's declared like
Copy code
ActiveCallCount, err = meter.Int64UpDownCounter(
		"calls.active",
		metric.WithDescription("Number of currently active calls"),
	)
And when a call is started I add 1 to the counter and when it ends I add -1 to the counter. Overall seems simple -- when I try to add this metric to my dashboard, I get very strange values. No matter what I put for the aggregator -- the values are very off... I am expecting a value near zero.
s
Hey @Dhruv B, please share what does the time series version of the metric show.
d
This is the time series
s
The every has 1980 seconds, is that intentional choice?
d
no, that was the value that popped in when I clicked timeseries. Changed it to 60, doesn't look much different
s
The default "Reduce To" is average for number panel, Can you change to number panel and share the request payload?
d
POST  /query_range
gives the following response
Copy code
{
  "status": "success",
  "data": {
    "type": "scalar",
    "meta": {
      "rowsScanned": 247792,
      "bytesScanned": 2712994,
      "durationMs": 91
    },
    "data": {
      "results": [
        {
          "queryName": "A",
          "columns": [
            {
              "name": "__result_0",
              "signal": "",
              "fieldContext": "",
              "fieldDataType": "",
              "queryName": "A",
              "aggregationIndex": 0,
              "meta": {},
              "columnType": "aggregation"
            }
          ],
          "data": [
            [
              -1276
            ]
          ]
        }
      ]
    }
  }
}
s
What does the value panel show? Does it
-1276
now? Can you please share the request payload?
d
let me get you the request, one sec
Here's the request
Copy code
{
  "schemaVersion": "v1",
  "start": 1755664954000,
  "end": 1756269754000,
  "requestType": "scalar",
  "compositeQuery": {
    "queries": [
      {
        "type": "builder_query",
        "spec": {
          "name": "A",
          "signal": "metrics",
          "source": "",
          "stepInterval": 200,
          "disabled": false,
          "filter": {
            "expression": "env.type = 'production'"
          },
          "having": {
            "expression": ""
          },
          "aggregations": [
            {
              "metricName": "calls.active",
              "timeAggregation": "latest",
              "spaceAggregation": "avg",
              "reduceTo": "sum"
            }
          ]
        }
      }
    ]
  },
  "formatOptions": {
    "formatTableResultForUI": false,
    "fillGaps": false
  },
  "variables": {}
}
s
The "Reduce To" is sum so it's showing this value. Did you explicitly change the "Reduce to" or was it Sum without your input. The sensible Reduce here would be "Avg of all values" or "Latest of values"
Not showing negative symbol is unexpected that's a bug.
d
I think it was sum w/o my input. I don't see an option for reduce to
oh nvm
I see the option
one second let me change it
image.png
this looks more promising
s
The "Sum" reduce to was the culprit. It was summing up the active calls for each interval over entire week
d
here's the request and response
Copy code
{
  "schemaVersion": "v1",
  "start": 1755665416000,
  "end": 1756270216000,
  "requestType": "scalar",
  "compositeQuery": {
    "queries": [
      {
        "type": "builder_query",
        "spec": {
          "name": "A",
          "signal": "metrics",
          "source": "",
          "stepInterval": 1980,
          "disabled": false,
          "filter": {
            "expression": "env.type = 'production'"
          },
          "having": {
            "expression": ""
          },
          "aggregations": [
            {
              "metricName": "calls.active",
              "timeAggregation": "latest",
              "spaceAggregation": "avg",
              "reduceTo": "last"
            }
          ]
        }
      }
    ]
  },
  "formatOptions": {
    "formatTableResultForUI": false,
    "fillGaps": false
  },
  "variables": {}
}
Copy code
{
  "status": "success",
  "data": {
    "type": "scalar",
    "meta": {
      "rowsScanned": 848969,
      "bytesScanned": 35198242,
      "durationMs": 1235
    },
    "data": {
      "results": [
        {
          "queryName": "A",
          "columns": [
            {
              "name": "__result_0",
              "signal": "",
              "fieldContext": "",
              "fieldDataType": "",
              "queryName": "A",
              "aggregationIndex": 0,
              "meta": {},
              "columnType": "aggregation"
            }
          ],
          "data": [
            [
              -1
            ]
          ]
        }
      ]
    }
  }
}
s
This one gives you the avg active calls in the most recent interval for the selected time period.
d
what if I change it to sum.
also dropped the time range to last 30 min
s
So imagine you have two processes emitting the metric, then each process would have their own "active" calls numbers If you change it to Sum, you are aggregating the total active calls across all instances (in other words across time series). For avg, you are you are aggregating the avg of active calls across all instances. Does that clarify what "Sum" and "Avg" do?
d
yea. This is a gauge like metric, so I think we want the latest and sum since we want a total across all instances.
thank you Srikanth -- appreciate your support 🙏