add log warning to starlark drop-fields example

This commit is contained in:
Steven Soroka 2020-11-27 12:20:21 -05:00
parent 11b83dbd54
commit 42eacb3a42
1 changed files with 5 additions and 1 deletions

View File

@ -10,6 +10,9 @@
# 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",
@ -17,10 +20,11 @@ expected_type = {
"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