Skip to content

Commit

Permalink
Fixes to add few span metrics attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rkothari007 committed Nov 2, 2023
1 parent 215cbfb commit 296ea6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import json
import logging
import random
import time
import uuid
Expand Down Expand Up @@ -57,6 +58,10 @@
"L9ECAV7KIM",
"LS4PSXUNUM",
"OLJCESPC7Z",
"OLJCESPC7Z",
"OLJCESPC7Z",
"OLJCESPC7Z",
"OLJCESPC7Z",
"HQTGWGPNH4",
]

Expand Down Expand Up @@ -115,10 +120,11 @@ def checkout(self):
start_time = time.time()

self.add_to_cart(user=user)

duration = time.time() - start_time
# skip checkout if the latency is more than a second
if (self.skip_checkout(duration)):
logging.info("skipping checkout, duration:", duration)
return
checkout_person = random.choice(people)
checkout_person["userId"] = user
Expand All @@ -132,12 +138,13 @@ def checkout_multi(self):
start_time = time.time()
for i in range(random.choice([2, 3, 4])):
self.add_to_cart(user=user)

duration = time.time() - start_time
# skip checkout if the latency is more than a second
if (self.skip_checkout(duration)):
return

logging.info("skipping checkout_multi, duration:", duration)
return

checkout_person = random.choice(people)
checkout_person["userId"] = user
self.client.post("/api/checkout", json=checkout_person)
Expand All @@ -155,5 +162,5 @@ def skip_checkout(self, duration):
skip_checkout_if_slow = getattr(Environment().parsed_options, 'skip_checkout_if_slow', True)
if skip_checkout_if_slow and duration > latency_threshold_secs:
return True


9 changes: 9 additions & 0 deletions src/otelcollector/otelcol-config-extras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@
# pipelines:
# traces:
# exporters: [spanmetrics, otlphttp/example]

connectors:
spanmetrics:
dimensions:
- name: app.product.id
- name: flag.productCatalogTimeout
dimensions_cache_size: 1000
aggregation_temporality: "AGGREGATION_TEMPORALITY_CUMULATIVE"
metrics_flush_interval: 15s
10 changes: 8 additions & 2 deletions src/productcatalogservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ func (p *productCatalog) checkProductFailure(ctx context.Context, id string) boo
span.AddEvent("error", trace.WithAttributes(attribute.String("message", fmt.Sprintf("GetFlag Failed: %s", flagName))))
return false
}
attribute.Boolean(flagName, ffResponse.GetFlag().Enabled)
span := trace.SpanFromContext(ctx)
span.SetAttributes(
attribute.Bool("flag.productCatalogFailure", ffResponse.GetFlag().Enabled),
)
return ffResponse.GetFlag().Enabled
}

Expand All @@ -302,7 +305,10 @@ func (p *productCatalog) checkProductTimeout(ctx context.Context, id string) boo
span.AddEvent("error", trace.WithAttributes(attribute.String("message", fmt.Sprintf("GetFlag Failed: %s", flagName))))
return false
}
attribute.Boolean(flagName, ffResponse.GetFlag().Enabled)
span := trace.SpanFromContext(ctx)
span.SetAttributes(
attribute.Bool("flag.productCatalogTimeout", ffResponse.GetFlag().Enabled),
)
return ffResponse.GetFlag().Enabled
}

Expand Down

0 comments on commit 296ea6a

Please sign in to comment.