From 06e4ae2d98cc25b7b1de8e1723f5bb525b5adb7c Mon Sep 17 00:00:00 2001 From: Sam Dillard Date: Sat, 13 Feb 2021 10:53:33 -0800 Subject: [PATCH] normalized types and added all metric tags --- .../starlark/testdata/schema_sizing.star | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/processors/starlark/testdata/schema_sizing.star b/plugins/processors/starlark/testdata/schema_sizing.star index f9ac50e0421fb..27cf2f0145b14 100644 --- a/plugins/processors/starlark/testdata/schema_sizing.star +++ b/plugins/processors/starlark/testdata/schema_sizing.star @@ -4,19 +4,21 @@ # logstash,environment_id=EN456,org_id=34un1084ygbHSJHDBF9j2u8@AdobeOrg,property_id=PR789,request_type=ingress,stack_id=engd asn=1313i,cache_response_code=202i,colo_code="LAX",colo_id=12i,compute_time=28736i,edge_end_timestamp=1611085500320i,edge_start_timestamp=1611085496208i,id="1b5c67ed-dfd0-4d30-99bd-84f0a9c5297b_76af1809-29d1-4b35-a0cf-39797458275c",parent_ray_id="00",processing_details="ok",rate_limit_id=0i,ray_id="76af1809-29d1-4b35-a0cf-39797458275c",request_bytes=7777i,request_host="engd-08364a825824e04f0a494115.reactorstream.dev",request_id="1b5c67ed-dfd0-4d30-99bd-84f0a9c5297b",request_result="succeeded",request_uri="/ENafcb2798a9be4bb7bfddbf35c374db15",response_code=200i,subrequest=false,subrequest_count=1i,user_agent="curl/7.64.1" 1611085496208 # # Example Output: -# sizing tag_count=5i,tag_key_avg_length=10.2,tag_value_avg_length=10.6,int_avg_length=4.9,int_count=10i,bool_avg_length=5,bool_count=1i,str_avg_length=25.4,str_count=10i 1611085496208 +# sizing,measurement=logstash,environment_id=EN456,org_id=34un1084ygbHSJHDBF9j2u8@AdobeOrg,property_id=PR789,request_type=ingress,stack_id=engd tag_count=5,tag_key_avg_length=10.2,tag_value_avg_length=10.6,int_avg_length=4.9,int_count=10,bool_avg_length=5,bool_count=1,str_avg_length=25.4,str_count=10 1611085496208 load("logging.star", "log") def apply(metric): new_metric = Metric("sizing") num_tags = len(metric.tags.items()) - new_metric.fields["tag_count"] = num_tags + new_metric.fields["tag_count"] = float(num_tags) new_metric.fields["tag_key_avg_length"] = _sum(map(len, metric.tags.keys())) / num_tags new_metric.fields["tag_value_avg_length"] = _sum(map(len, metric.tags.values())) / num_tags new_metric.tags["measurement"] = metric.name + new_metric.tags.update(metric.tags) + ints, floats, bools, strs = [], [], [], [] for field in metric.fields.items(): value = field[1] @@ -48,11 +50,11 @@ def produce_pairs(metric, li, field_type): lens = elem_lengths(li) counts = count_lengths(lens) max_value = max(counts) - metric.fields["{}_avg_length".format(field_type)] = mean(lens) - metric.fields["{}_count".format(field_type)] = len(li) - # metric.fields["{}_variance".format(field_type)] = variance(lens) + metric.fields["{}_avg_length".format(field_type)] = float(mean(lens)) + metric.fields["{}_count".format(field_type)] = float(len(li)) + # metric.fields["{}_variance".format(field_type)] = float(variance(lens)) # log.debug("get_key: {}".format(get_key(counts, max_value))) - # metric.fields["{}_mode".format(field_type)] = get_key(counts, max_value) + # metric.fields["{}_mode".format(field_type)] = float(get_key(counts, max_value)) def elem_lengths(li): if type(li[0]) in ("int", "float", "bool"):