Forcing tsDecl to return array of all zeros

I have a tsDecl metric that should return a zero value for each timestamp.
The problem is that when this metric is evaluated, the response array is of length 1 in the following way: [0.0] (i.e since value is zero at each point, only a single entry is returned to represent zero at each point)

This causes issues in the front end UI, as a graph of a single point is plotted for this metric.
This seems to impact all other metrics on the same plot, causing them to not display any data for that time range (only the single point from the tsDecl is plotted)

tsDecl metric:

{
   "id": "metricId",
   "name": "metricName",
   "srcType": "myType",
   "description": "",
   "tsDecl": {
       "data": "myData",
       "start": "timestamp",
       "treatment": "PREVIOUS",
       "value": "value",
       "transform": "fillMissing(this,0)"
   }
 }

Network Response when Evaluated:

{
  "result" : {
    "id" : {
      "metricName" : {
        "type" : "NormTimeseriesDouble",
        "m_start" : "2017-06-24T22:30:00",
        "m_end" : "2017-07-02T23:00:00",
        "m_data" : [ 0.0 ],
        "m_interval" : "HALF_HOUR",
        "m_timeZone" : "NONE",
        "m_sourceInfo" : {
          "source" : {
            "id" : "id",
            "moduleName" : "",
            "typeName" : "myType"
          }

Graph:

Note: Other metrics selected will plot correctly when the tsDecl returning [0.0] is unselected

Is there any way we can force the tsDecl metric to return an array of zeros for each timestamp in the range?

1 Like

Why do you need a tsDecl metric? The below metric willl return a flat line at 0

{
   "id": "metricId",
   "name": "metricName",
   "srcType": "myType",
   "description": "",
   "expression": "identity(0)"
 }

BTW how are you charting that tsDecl metric? Is that c3Viz()? You should not use the m_data field directly, instead you should call the data() method. m_data is an implementation detail while data() is the API. Its possible (now or in the future) that m_data is compressed to a pair of 0s to void sending unnecessary data over the wire?

tsDecl is needed to get a time series output. The result of the metric is not always all zero, it depends on the time range of evaluation.
But if it is all zero I want to avoid this behaviour.

The chart is being produced in React via a call to multiple metrics like below;

<FilterComponent
       title="Metrics"
       tags={[
         "metric.myMetric1",
         "metric.myMetric2"
       ]}

I think this uses the data() method

Might be best to just produce a wrapper function giving the desired output in JS, then react can use this instead of calling the metric directly.

If your client is type-aware, then you should use the Timeseries#data member function:

var data = result.id.metricName.data();

If your client is not type-aware, then the network response should contain a data array that you can use directly:

var data = result.id.metricName.data;

If there is no data() member function, then your client is not type-aware.

See the rest-binding documentation topic for more information on the difference between type-aware and non-type-aware clients.

Thanks guys that helped @matt @rileysiebel :slightly_smiling_face:

1 Like