Forward a variable in a compound metric


#1

Hi,

If I have a metric A declaring a variable myVar:

{
  "id": "A",
  "name": "A",
  "srcType": "MyType",
  "actionDecl": {
    "action": "myAction(myVar)",
  },
  "variables": [
    {
      "name": "myVar"
    }
  ]
 }

How can I set myVar when calling the compound metric B?

{
    "id": "B",
    "name": "B",
    "expression": "A"
}

I have tried defining variables in B as well, but even though the eval metrics with bindings:{myVar: 42} is properly executed, myVar is not set to 42. How to provide myVar to the metric A from B?

Thanks


#2

I see that you have myAction as an actionDecl metric. I’m guessing you have defined the type as:

type MyType {
    myAction: function(obj: Obj, spec: TSEvalSpec, metric: Metric, myVar: double) js server
}

Since your metric is already an actionDecl metric, you do NOT need to define any variables but provide myVar as an argument in your function definition on the type:

{
  "id": "A",
  "name": "A",
  "srcType": "MyType",
  "actionDecl": {
    "action": "myAction",
  }
 }

Your compound metric can still be:

{
    "id": "B",
    "name": "B",
    "expression": "A"
}

and your evalMetric call can now set the bindings as: bindings:{myVar: 42} e.g.

> MyType.evalMetrics({
>   ids: ['foo'], expressions:['B'], start:"2010-01-01", end:"2015-01-01", interval:"MONTH", bindings: {myVar: 42}
> })

The above behavior is expected to work and if you encounter any issues, that would mean that there is a bug and you should file a ticket for it and we’ll do our best to fix it asap.


#3

Hi Rohit,

I believe you forgot myVar as a myAction argument in the definition of the metric A.
With it (myAction(myVar)) it works exactly as you described, unless I use the cache option in which case the metric seems to make it to the cache once and then to be re-used ignoring the argument. Will open a ticket for that, meanwhile I’ll disable the cache.

Thanks


#4

Hi Irelea

Currently caching action decl metrics is not supported in the platform. This is thrown as an explicit exception in v7.7 of the server but not in the earlier versions.

Yes I would recommend disabling the cache for now and we can visit if/when we should support caching for action decl based metrics