Skip to content

Commit

Permalink
add log warning to starlark drop-fields example
Browse files Browse the repository at this point in the history
(cherry picked from commit 42eacb3)
  • Loading branch information
ssoroka committed Dec 1, 2020
1 parent 28313b9 commit a57a0d8
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
# measurement,host=hostname a=1i,b=4.2,c=42.0,d="v3.14",e=true,f=23.0 1597255410000000000
# measurement,host=hostname a=1i,c=42.0,d="v3.14",e=true,f=23.0 1597255410000000000

load("logging.star", "log")
# loads log.debug(), log.info(), log.warn(), log.error()

expected_type = {
"a": "int",
"b": "float",
"c": "float",
"d": "string",
"e": "bool"
}

def apply(metric):
for k, v in metric.fields.items():
if type(v) != expected_type.get(k, type(v)):
metric.fields.pop(k)
log.warn("Unexpected field type dropped: metric {} had field {} with type {}, but it is expected to be {}".format(metric.name, k, type(v), expected_type.get(k, type(v))))

return metric

0 comments on commit a57a0d8

Please sign in to comment.