Skip to content

Commit bf48916

Browse files
committed
Return a document even when no cost is given
1 parent 8d7a26c commit bf48916

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

packages/ess_billing/data_stream/billing/agent/stream/cel.yml.hbs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ program: |
5959
}
6060
}).do_request().as(resp, resp.StatusCode == 200
6161
?
62-
bytes(resp.Body).decode_json().as(body,
62+
// Response is successful, but did we get any data?
63+
bytes(resp.Body).decode_json().as(body, has(body.instances) && size(body.instances) > 0
64+
?
6365
{
6466
"events": body.instances.map(instance, instance.product_line_items.map(line_item,
6567
{
@@ -73,17 +75,40 @@ program: |
7375
})
7476
}
7577
}
76-
)).flatten(), // Pass line_items as events, with added info
78+
)).flatten(), // Pass line_items as events, with added info
7779
"cursor": {
7880
"last_to": state.to
7981
},
8082
// Are we more than 1 day behind?
8183
"want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
8284
"api_key": state.api_key,
83-
"organization_id": state.organization_id
85+
"organization_id": state.organization_id,
86+
}
87+
:
88+
// We don't have any data, but we still need to return an event
89+
// Otherwise the "want_more" logic will not work
90+
{
91+
"events": [{
92+
"ess": {
93+
"billing": {
94+
"organization_id": state.organization_id,
95+
"from": state.from,
96+
"to": state.to,
97+
"total_ecu": 0,
98+
}
99+
}
100+
}],
101+
"cursor": {
102+
"last_to": state.to
103+
},
104+
// Are we more than 1 day behind?
105+
"want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
106+
"api_key": state.api_key,
107+
"organization_id": state.organization_id,
84108
}
85109
)
86110
:
111+
// Response was not successful, return an error event
87112
{
88113
"events": {
89114
"error": {
@@ -102,7 +127,7 @@ program: |
102127
},
103128
"want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
104129
"api_key": state.api_key,
105-
"organization_id": state.organization_id
130+
"organization_id": state.organization_id,
106131
}
107132
)
108133
)

packages/ess_billing/data_stream/billing/elasticsearch/ingest_pipeline/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ processors:
135135
if (regionGeo.containsKey(region)) {
136136
ctx.cloud.geo = regionGeo[region];
137137
}
138+
ignore_failure: true
138139
- set:
139140
if: "ctx.cloud.geo.name == null"
140141
tag: set_unknown_geo

0 commit comments

Comments
 (0)