Skip to content

Commit

Permalink
normalized types and added all metric tags
Browse files Browse the repository at this point in the history
  • Loading branch information
samhld committed Feb 13, 2021
1 parent 6c1ade8 commit 06e4ae2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions plugins/processors/starlark/testdata/schema_sizing.star
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 06e4ae2

Please sign in to comment.