Skip to content

Commit

Permalink
Added better null handling script
Browse files Browse the repository at this point in the history
  • Loading branch information
agithomas committed Jul 8, 2024
1 parent 7c544fd commit 9551350
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
---
description: Pipeline for AWS Health metrics
processors:

- script:
if: "ctx.aws != null && ctx.aws.awshealth != null && ctx.aws.awshealth.end_time == '0001-01-01T00:00:00.000Z'"
"lang": "painless"
"source": "ctx.aws.awshealth.end_time = null"

- script:
if: "ctx.aws != null && ctx.aws.awshealth != null"
lang: painless
source: |
if (ctx.aws.awshealth.end_time == null) {
ctx.drop_end_time = true;
} else {
ctx.drop_end_time = false;
source: |-
boolean drop(Object o) {
if (o == null || o == '') {
return true;
} else if (o instanceof Map) {
((Map) o).values().removeIf(v -> drop(v));
return (((Map) o).size() == 0);
} else if (o instanceof List) {
((List) o).removeIf(v -> drop(v));
return (((List) o).length == 0);
}
return false;
}
- remove:
if: "ctx.drop_end_time == true"
ignore_missing: true
field: aws.awshealth.end_time

- remove:
ignore_missing: true
field: drop_end_time
drop(ctx);
description: Drops null/empty values recursively.

on_failure:
- set:
Expand Down

0 comments on commit 9551350

Please sign in to comment.