Returning the Metric Record Count in a Slack message

mark
Level 1
Returning the Metric Record Count in a Slack message

Hello,



I have set up a scenario which returns a Slack message upon completion, along with some standard variables (e.g., ${scenarioName}). By following the documentation here https://doc.dataiku.com/dss/latest/scenarios/variables.html ("Retrieving the value of a metric") I have been able to get the entire output from the metrics computation (${stepOutput_the_metrics}).



However, I would like to limit the content of the Slack message to the number of rows of the dataset (i.e., the value of the COUNT_RECORDS metric). When I try and follow the rest of the documentation, I cannot follow; especially the section "If the goal is to retrieve the value of the metric col_stats:MIN:cost, with a bit of filtering one obtains this status with ${filter(parseJson(stepOutput_the_metrics)[โ€˜PROJ.computedโ€™].computed, x, x.metricId == โ€˜col_stats:MIN:costโ€™)[0].value}"



I want to replicate this, but for my circumstances, but I am unable to. What does the x refer to here? 



If I wanted to the value of the metric "metricId:records:COUNT_RECORDS", how would I do this?

0 Kudos
3 Replies
Alex_Combessie
Dataiker Alumni

Hi Mark,



Let's assume that inside your scenario, you have one "Compute metrics" step named "the_metrics", which has one dataset called "test" in the project "SANDBOX" with the metric "records:COUNT_RECORDS" configured.





Then you can retrieve the value of the metric using:



${filter(parseJson(stepOutput_the_metrics)[โ€˜SANDBOX.testโ€™].computed, x, x.metricId == โ€˜records:COUNT_RECORDSโ€™)[0].value}



I put in bold the parameters that you need to change:



1. Name of the "Compute metrics" step: "the_metrics"



2. Project key: "SANDBOX"



3. Dataset name: "test"



4. Metric identifier: "records:COUNT_RECORDS"



Hope it helps,



Alex

0 Kudos
madisondunn8
Level 1

Hello, I'm trying to do something very similar but in an email message and I cannot get it to work. I have a dataset called "RECORDS" and in the scenario, I am first running the metrics, then in the next step sending an email, trying to call the record count. Within my dataset RECORDS, I believe I have the record count metric turned on but when I try to call it in my email step using this: 

${filter(parseJson(stepOutput_metrics)[โ€˜projectkey.RECORDSโ€™].computed, x, x.metricId == โ€˜metricId:records:COUNT_RECORDSโ€™)[0].value}

When I run the step, I always get the error ' freemarker.core.ParseException
Syntax error in template "tmpl0" in line 8, column 40: Lexical error: encountered "\u2018" (8216), after "".' 

Any suggestions? I'm very confused about how to get the output itself from the metrics computation (${stepOutput_metrics}) as nothing returns when I call that. Please advise. 

0 Kudos
Turribeach

Please always start a new thread, as otherwise threads can't be marked as solved. You can reference other threads in your post if you want. Your problem is that you need to use a name without spaces for your metrics step (like Compute_metrics) and also use that name in your formula (like stepOutput_Compute_metrics). If it doesn't work start a new thread. Thanks

0 Kudos

Labels

?
Labels (3)
A banner prompting to get Dataiku