Hi @richcollier
I was able to create the watcher and simulate some notifications. I modified the actions to notify to slack when there is a value below 0.9 (It will be 0.8 once it works as expected).
Here is the JSON content of the watcher
{
"trigger": {
"schedule": {
"interval": "5m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"traces-apm*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"services": {
"terms": {
"field": "service.name",
"size": 30
},
"aggs": {
"avg_apdexscore": {
"avg": {
"field": "labels.apdexscore"
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"source": """
return ctx.payload.aggregations.services.buckets.stream()
.filter(services -> services.avg_apdexscore.value < 0.9)
.count() > 0
""",
"lang": "painless"
}
},
"actions": {
"notify-slack": {
"throttle_period_in_millis": 300000,
"transform": {
"script": {
"source": """
return ctx.payload.aggregations.services.buckets.stream()
.filter(services -> services.avg_apdexscore.value < 0.9)
.collect(Collectors.toList());
""",
"lang": "painless"
}
},
"slack": {
"message": {
"text": """{{#ctx.payload._value}} service.name={{key}} is below 0.9 with labels.apdexscore={{avg_apdexscore.value}}
{{/ctx.payload._value}}"""
}
}
}
}
}
And this is a Simulate watch
{
"watch_id": "_inlined_",
"node": "**************",
"state": "executed",
"@timestamp": "2022-06-22T13:30:32.298895082Z",
"user": "**************",
"status": {
"state": {
"active": true,
"timestamp": "2022-06-22T13:30:32.298Z"
},
"last_checked": "2022-06-22T13:30:32.298Z",
"last_met_condition": "2022-06-22T13:30:32.298Z",
"actions": {
"notify-slack": {
"ack": {
"timestamp": "2022-06-22T13:30:32.298Z",
"state": "ackable"
},
"last_execution": {
"timestamp": "2022-06-22T13:30:32.298Z",
"successful": true
},
"last_successful_execution": {
"timestamp": "2022-06-22T13:30:32.298Z",
"successful": true
}
}
},
"execution_state": "executed",
"version": -1
},
"trigger_event": {
"type": "manual",
"triggered_time": "2022-06-22T13:30:32.298Z",
"manual": {
"schedule": {
"scheduled_time": "2022-06-22T13:30:32.298Z"
}
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"traces-apm*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"services": {
"terms": {
"field": "service.name",
"size": 30
},
"aggs": {
"avg_apdexscore": {
"avg": {
"field": "labels.apdexscore"
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"source": "\n return ctx.payload.aggregations.services.buckets.stream() \n .filter(services -> services.avg_apdexscore.value < 0.9) \n .count() > 0 \n ",
"lang": "painless"
}
},
"metadata": {
"name": "Apdex score by service",
"xpack": {
"type": "json"
}
},
"result": {
"execution_time": "2022-06-22T13:30:32.298Z",
"execution_duration": 2952,
"input": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 52,
"failed": 0,
"successful": 52,
"skipped": 0
},
"hits": {
"hits": [],
"total": 10000,
"max_score": null
},
"took": 2950,
"timed_out": false,
"aggregations": {
"services": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 124695,
"avg_apdexscore": {
"value": 0.9914766892585747
},
"key": "service1"
},
{
"doc_count": 65515,
"avg_apdexscore": {
"value": 0.7985335195530726
},
"key": "service2"
},
{
"doc_count": 38725,
"avg_apdexscore": {
"value": 0.9988324576765908
},
"key": "service3"
},
{
"doc_count": 34317,
"avg_apdexscore": {
"value": 0.9955449955449955
},
"key": "service4"
},
{
"doc_count": 22326,
"avg_apdexscore": {
"value": 0.9893672199170125
},
"key": "service5"
},
{
"doc_count": 19625,
"avg_apdexscore": {
"value": 0.9994541484716157
},
"key": "service6"
},
{
"doc_count": 18998,
"avg_apdexscore": {
"value": 0.9980136208853575
},
"key": "service7"
},
{
"doc_count": 18692,
"avg_apdexscore": {
"value": 0.8258392362180474
},
"key": "service8"
},
{
"doc_count": 17580,
"avg_apdexscore": {
"value": 0.7917981072555205
},
"key": "service9"
},
{
"doc_count": 12413,
"avg_apdexscore": {
"value": 0.9996461429582448
},
"key": "service10"
},
{
"doc_count": 10132,
"avg_apdexscore": {
"value": 0.9968916518650088
},
"key": "service11"
},
{
"doc_count": 9431,
"avg_apdexscore": {
"value": 0.9986376021798365
},
"key": "service12"
},
{
"doc_count": 9045,
"avg_apdexscore": {
"value": 0.8404023926046764
},
"key": "service13"
},
{
"doc_count": 8522,
"avg_apdexscore": {
"value": 0.9949109414758269
},
"key": "service14"
},
{
"doc_count": 8322,
"avg_apdexscore": {
"value": 0.8571428571428571
},
"key": "service15"
},
{
"doc_count": 7167,
"avg_apdexscore": {
"value": 0.8769911504424779
},
"key": "service16"
},
{
"doc_count": 5987,
"avg_apdexscore": {
"value": 0.8183503243744208
},
"key": "service17"
},
{
"doc_count": 4937,
"avg_apdexscore": {
"value": 0.8734817813765182
},
"key": "service18"
},
{
"doc_count": 4350,
"avg_apdexscore": {
"value": 0.867335562987737
},
"key": "service19"
},
{
"doc_count": 4080,
"avg_apdexscore": {
"value": 0.9984984984984985
},
"key": "service20"
},
{
"doc_count": 3179,
"avg_apdexscore": {
"value": 0.8579545454545454
},
"key": "service21"
},
{
"doc_count": 2190,
"avg_apdexscore": {
"value": 0.8739224137931034
},
"key": "service22"
},
{
"doc_count": 780,
"avg_apdexscore": {
"value": 0.991701244813278
},
"key": "service23"
},
{
"doc_count": 30,
"avg_apdexscore": {
"value": 1
},
"key": "service24"
}
]
}
}
},
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"traces-apm*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"services": {
"terms": {
"field": "service.name",
"size": 30
},
"aggs": {
"avg_apdexscore": {
"avg": {
"field": "labels.apdexscore"
}
}
}
}
}
}
}
}
},
"condition": {
"type": "script",
"status": "success",
"met": true
},
"actions": [
{
"id": "notify-slack",
"type": "slack",
"status": "simulated",
"transform": {
"type": "script",
"status": "success",
"payload": {
"_value": [
{
"doc_count": 65515,
"avg_apdexscore": {
"value": 0.7985335195530726
},
"key": "service2"
},
{
"doc_count": 18692,
"avg_apdexscore": {
"value": 0.8258392362180474
},
"key": "service3"
},
{
"doc_count": 17580,
"avg_apdexscore": {
"value": 0.7917981072555205
},
"key": "service4"
},
{
"doc_count": 9045,
"avg_apdexscore": {
"value": 0.8404023926046764
},
"key": "service7"
},
{
"doc_count": 8322,
"avg_apdexscore": {
"value": 0.8571428571428571
},
"key": "service9"
},
{
"doc_count": 7167,
"avg_apdexscore": {
"value": 0.8769911504424779
},
"key": "service10"
},
{
"doc_count": 5987,
"avg_apdexscore": {
"value": 0.8183503243744208
},
"key": "service16"
},
{
"doc_count": 4937,
"avg_apdexscore": {
"value": 0.8734817813765182
},
"key": "service17"
},
{
"doc_count": 4350,
"avg_apdexscore": {
"value": 0.867335562987737
},
"key": "service20"
},
{
"doc_count": 3179,
"avg_apdexscore": {
"value": 0.8579545454545454
},
"key": "service21"
},
{
"doc_count": 2190,
"avg_apdexscore": {
"value": 0.8739224137931034
},
"key": "service24"
}
]
}
},
"slack": {
"message": {
"from": "_inlined_",
"text": " service.name=service2 is below 0.9 with labels.apdexscore=0.7985335195530726 \n service.name=service3 is below 0.9 with labels.apdexscore=0.8258392362180474 \n service.name=service4 is below 0.9 with labels.apdexscore=0.7917981072555205 \n service.name=service7 is below 0.9 with labels.apdexscore=0.8404023926046764 \n service.name=service9 is below 0.9 with labels.apdexscore=0.8571428571428571 \n service.name=service10 is below 0.9 with labels.apdexscore=0.8769911504424779 \n service.name=service16 is below 0.9 with labels.apdexscore=0.8183503243744208 \n service.name=service17 is below 0.9 with labels.apdexscore=0.8734817813765182 \n service.name=service20 is below 0.9 with labels.apdexscore=0.867335562987737 \n service.name=service21 is below 0.9 with labels.apdexscore=0.8579545454545454 \n service.name=service24 is below 0.9 with labels.apdexscore=0.8739224137931034 \n"
}
}
}
]
},
"messages": []
}
The simulate is working and sends the notifications to an slack channel. But when I save it I don't receive more notifications. Why could it be?
Kind regards