Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profiling] Calculate CO2 emission and costs (#101979)
This PR moves the cost and CO2 calculations from Kibana into the ES profiling API. The calculations are improved by applying AWS price lists and co2/cpu/energy data from instance types (AWS, GCP, Azure). The stacktraces and flamegraph APIs are extended with the cost and CO2 values in a backwards compatible way. * Add CO2 and costs calculator * Query stacktrace events aggregated by (host.id,stacktrace.id) * Add co2Factor, costFactor and count to StackTraces * Add co2Factor, costFactor and count to Flamegraph * Require field 'requested_duration' in stacktraces request * Implement a PoC calculation for co2 and costs * Rename co2/costs response fields * Use helper function for fetching single values from search response * ArrayList -> List * Remove hot debug logs * Load profiling costs from file * Update profiling-costs.json.gz * Use method references for StopWatch.report() * Do co2/cost in parallel to stacktrace metadata queries * Move CO2 calculations into a separate class * Move cost calculations into a separate class * Cleanups / address comments * Restore stack_trace_events array and fix tests * Add comments for the query bucket sizes * Fix tests * Fix HostMetadata * Cleanups * More cleanups * Extract DatacenterInstance from host metadata * Improve host metadata query to only fetch relevant docs * Calculate wattsPerCore from host CPU architecture * Get PUE and CO2TonsPerKWH from provider and region * Remove filter for AWS host metadata * Add changelog * Fix host metadata query and query sizes * Add unit test for HostMetadata * Reduce number of host metadata docs to be retrieved * Add unit tests for CO2 Calculator * Add unit tests for cost Calculator * Fix tests for CO2 calculations for known instance type * Address PR comments * Add region to InstanceType.toString() * Add optional request param 'custom_cost_factor' * Use TraceEvent instead of Long in GetStackTracesResponse.java * Fix integration tests * Add customCostFactor to cost calculator * Fix exception in KvIndexResolver#resolve in DEBUG mode * Add integration tests * Rename CostsService -> InstanceTypeService * Apply review comments * Use import static java.util.Map.entry * Remove debug log from KvIndexResolver * Address review comments * Address review comments --------- Co-authored-by: Daniel Mitterdorfer <daniel.mitterdorfer@elastic.co>
- Loading branch information
1 parent
1dfaac7
commit 0cce4ae
Showing
36 changed files
with
1,375 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 101979 | ||
summary: Calculate CO2 and emmission and costs | ||
area: Application | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
.../core/template-resources/src/main/resources/profiling/index-template/profiling-costs.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
x-pack/plugin/profiling/src/internalClusterTest/resources/data/profiling-events-all.ndjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
x-pack/plugin/profiling/src/internalClusterTest/resources/data/profiling-hosts.ndjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"create": {"_index": "profiling-hosts", "_id": "eLH27YsBj2lLi3tJYlvr"}} | ||
{"profiling.project.id": 100, "host.id": "8457605156473051743", "@timestamp": 1700504426, "ecs.version": "1.12.0", "profiling.agent.build_timestamp": 1688111067, "profiling.instance.private_ipv4s": ["192.168.1.2"], "ec2.instance_life_cycle": "on-demand", "profiling.agent.config.map_scale_factor": 0, "ec2.instance_type": "i3.2xlarge", "profiling.host.ip": "192.168.1.2", "profiling.agent.config.bpf_log_level": 0, "profiling.host.sysctl.net.core.bpf_jit_enable": 1, "profiling.agent.config.file": "/etc/prodfiler/prodfiler.conf", "ec2.local_ipv4": "192.168.1.2", "profiling.agent.config.no_kernel_version_check": false, "profiling.host.machine": "x86_64", ",profiling.host.tags": ["cloud_provider:aws", "cloud_environment:qa", "cloud_region:eu-west-1"], "profiling.agent.config.probabilistic_threshold": 100, "profiling.agent.config.disable_tls": false, "profiling.agent.config.tracers": "all", "profiling.agent.start_time": 1700090045589, "profiling.agent.config.max_elements_per_interval": 800, "ec2.placement.region": "eu-west-1", "profiling.agent.config.present_cpu_cores": 8, "profiling.host.kernel_version": "9.9.9-0-aws", "profiling.agent.config.bpf_log_size": 65536, "profiling.agent.config.known_traces_entries": 65536, "profiling.host.sysctl.kernel.unprivileged_bpf_disabled": 1, "profiling.agent.config.verbose": false, "profiling.agent.config.probabilistic_interval": "1m0s", "ec2.placement.availability_zone_id": "euw1-az1", "ec2.security_groups": "", "ec2.local_hostname": "ip-192-168-1-2.eu-west-1.compute.internal", "ec2.placement.availability_zone": "eu-west-1c", "profiling.agent.config.upload_symbols": false, "profiling.host.sysctl.kernel.bpf_stats_enabled": 0, "profiling.host.name": "ip-192-168-1-2", "ec2.mac": "00:11:22:33:44:55", "profiling.host.kernel_proc_version": "Linux version 9.9.9-0-aws", "profiling.agent.config.cache_directory": "/var/cache/optimyze/", "profiling.agent.version": "v8.12.0", "ec2.hostname": "ip-192-168-1-2.eu-west-1.compute.internal", "profiling.agent.config.elastic_mode": false, "ec2.ami_id": "ami-aaaaaaaaaaa", "ec2.instance_id": "i-0b999999999999999" } |
Oops, something went wrong.