Skip to content

Commit

Permalink
[Profiling] Always allow for CO2 and cost defaults
Browse files Browse the repository at this point in the history
There are two possibilities to retrieve flamegraph data:

* Via the native UI
* Via the APM integration

Depending on the scenario, different request parameters are set. While
we have improved the CO2 and cost calculation for the native UI, the
host id, which is required for an improved CO2 and cost calculation, is
not yet available for the APM integration.

So far we've not performed this calculation at all because there were
no associated host data for stacktraces. Consequently, we've returned
zero values in all cases. With this commit we associate "dummy" host
data so the CO2 and cost calculation falls back to default values. Once
a host id is available for that case as well, we will instead use the
improved calculations.
  • Loading branch information
danielmitterdorfer committed Feb 6, 2024
1 parent 2a298a7 commit bc6a3d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public void testGetStackTracesFromAPMWithMatchNoDownsampling() throws Exception
assertEquals(39, stackTrace.fileIds.size());
assertEquals(39, stackTrace.frameIds.size());
assertEquals(39, stackTrace.typeIds.size());
assertTrue(stackTrace.annualCO2Tons > 0.0d);
assertTrue(stackTrace.annualCostsUSD > 0.0d);

assertNotNull(response.getStackFrames());
StackFrame stackFrame = response.getStackFrames().get("fhsEKXDuxJ-jIJrZpdRuSAAAAAAAAFtj");
Expand Down Expand Up @@ -141,6 +143,8 @@ public int hashCode() {
assertEquals(39, stackTrace.fileIds.size());
assertEquals(39, stackTrace.frameIds.size());
assertEquals(39, stackTrace.typeIds.size());
assertTrue(stackTrace.annualCO2Tons > 0.0d);
assertTrue(stackTrace.annualCostsUSD > 0.0d);

assertNotNull(response.getStackFrames());
StackFrame stackFrame = response.getStackFrames().get("fhsEKXDuxJ-jIJrZpdRuSAAAAAAAAFtj");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,8 @@ private void searchGenericEventGroupedByStackTrace(
SingleBucketAggregation sample = searchResponse.getAggregations().get("sample");
StringTerms stacktraces = sample.getAggregations().get("group_by");

// When we switch to aggregation by (hostID, stacktraceID) we need to change the empty List to this.
// List<HostEventCount> hostEventCounts = new ArrayList<>(MAX_TRACE_EVENTS_RESULT_SIZE);
// Related: https://github.com/elastic/prodfiler/issues/4300
// See also the aggregation in searchEventGroupedByStackTrace() for the other parts of the change.
List<HostEventCount> hostEventCounts = Collections.emptyList();
// When we retrieve host data for generic events, we need to adapt the handler similar to searchEventGroupedByStackTrace().
List<HostEventCount> hostEventCounts = new ArrayList<>(stacktraces.getBuckets().size());

// aggregation
Map<String, TraceEvent> stackTraceEvents = new TreeMap<>();
Expand All @@ -288,6 +285,8 @@ private void searchGenericEventGroupedByStackTrace(
totalSamples += count;

String stackTraceID = stacktraceBucket.getKeyAsString();
// For now, add a dummy-entry so CO2 and cost calculation can operate. In the future we will have one value per host.
hostEventCounts.add(new HostEventCount("unknown", stackTraceID, (int) count));
TraceEvent event = stackTraceEvents.get(stackTraceID);
if (event == null) {
event = new TraceEvent(stackTraceID);
Expand Down

0 comments on commit bc6a3d8

Please sign in to comment.