datadog-agent icon indicating copy to clipboard operation
datadog-agent copied to clipboard

processes: Autodetect service name for a spring boot application jar

Open amarziali opened this issue 1 year ago • 6 comments

What does this PR do?

This PR Adds the capability to autodetect a java spring boot service name by looking up the value of its property spring.application.name

A spring boot application can load properties from:

  • the system properties (-Dkey=value supplied along with the java exec)
  • the arguments (supplied as --key=value)
  • the env variables
  • the properties (.properties or .yaml/.yml). Those can reside
  • on the filesystem
  • inside the jar (if the location is the classpath)

This extractor is able to resolve the location above simulating how spring boot is loading its properties. Please note that, for performances reasons, we're only looking in the first level of the jar file (not recursing by introspecting jar file inside the jar that would probably require offloading somewhere this buffer)

We're just looking at the jar file table (jar is a zip) and eventually extracting only the property files (or yaml) that matches the location patterns

It requires a couple of modules in order to:

  • Use ANT style matchers for locations (it differs a bit from standard golang glob)
  • Parse .properties files (java key value)
  • Eventually resolve ${someprop} by looking up the value of someprop

Motivation

Simplify the onboarding by improving the default service naming generation

Additional Notes

Please note that this extraction is opt in (system_probe_config.process_service_inference.use_improved_algorithm has to be explicitly set to true)

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

Reviewer's Checklist

  • [ ] If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • [ ] Use the major_change label if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote.
  • [ ] A release note has been added or the changelog/no-changelog label has been applied.
  • [ ] Changed code has automated tests for its functionality.
  • [ ] Adequate QA/testing plan information is provided. Except if the qa/skip-qa label, with required either qa/done or qa/no-code-change labels, are applied.
  • [ ] At least one team/.. label has been applied, indicating the team(s) that should QA this change.
  • [ ] If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • [ ] If applicable, the need-change/operator and need-change/helm labels have been applied.
  • [ ] If applicable, the k8s/<min-version> label, indicating the lowest Kubernetes version compatible with this feature.
  • [ ] If applicable, the config template has been updated.

amarziali avatar Feb 12 '24 10:02 amarziali

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: f11fd5ca-e849-4edf-9eed-d8c33b4f2bc9 Baseline: 4666ca6225a49fbb7fbc8a9f9bc6b23770565586 Comparison: 7a5fae6048edf040efb10b33f7f0627058f1d255

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

Experiments with missing or malformed data

  • basic_py_check

Usually, this warning means that there is no usable optimization goal data for that experiment, which could be a result of misconfiguration.

No significant changes in experiment optimization goals

Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI
file_to_blackhole % cpu utilization -0.42 [-7.01, +6.17]

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
idle memory utilization +0.89 [+0.86, +0.92]
process_agent_real_time_mode memory utilization +0.66 [+0.63, +0.70]
process_agent_standard_check memory utilization +0.47 [+0.43, +0.52]
uds_dogstatsd_to_api_cpu % cpu utilization +0.34 [-1.10, +1.78]
tcp_syslog_to_blackhole ingress throughput +0.28 [+0.22, +0.33]
file_tree memory utilization +0.18 [+0.10, +0.27]
process_agent_standard_check_with_stats memory utilization +0.04 [+0.01, +0.07]
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.00, +0.00]
uds_dogstatsd_to_api ingress throughput -0.00 [-0.00, +0.00]
trace_agent_json ingress throughput -0.02 [-0.07, +0.03]
trace_agent_msgpack ingress throughput -0.03 [-0.04, -0.01]
file_to_blackhole % cpu utilization -0.42 [-7.01, +6.17]
otel_to_otel_logs ingress throughput -2.20 [-2.84, -1.56]

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

pr-commenter[bot] avatar Feb 12 '24 11:02 pr-commenter[bot]

Go Package Import Differences

Baseline: 4666ca6225a49fbb7fbc8a9f9bc6b23770565586 Comparison: 7a5fae6048edf040efb10b33f7f0627058f1d255

binaryosarchchange
process-agentlinuxamd64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend
process-agentlinuxarm64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend
process-agentwindowsamd64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend
process-agentdarwinamd64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend
process-agentdarwinarm64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend
heroku-process-agentlinuxamd64
+4, -0
+github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java
+github.com/rickar/props
+github.com/vibrantbyte/go-antpath/antpath
+github.com/vibrantbyte/go-antpath/extend

cit-pr-commenter[bot] avatar Feb 12 '24 12:02 cit-pr-commenter[bot]

So one thing we need to do is to put this behind a feature flag. We don't want it enabled before we are ready, and we will probably want to give users control over the name generated so we don't break customers who were using the old algorithms to name their USM services.

The injection code doesn't import from the agent; it's just a copy-paste. Not ideal, I realize, but one day I hope to get the go portion of the injection code into the agent and that will remove the problem.

jonbodner avatar Feb 12 '24 21:02 jonbodner

please set the milestone 7.53 and add qa/done label (since you have UTs)

guyarb avatar Feb 21 '24 11:02 guyarb

@amarziali since we're still reviewing the PR, please try to avoid rebase as Github does not allow to show the differences between reviews cycles

guyarb avatar Feb 28 '24 03:02 guyarb

Please go over the trace logs here, I suspect that the majority are redundant and does not add useful debugging information. you need to remember that the code can be executed multiple times concurrently for different applications, having logs like "loaded" or "not spring app" won't give any hint to the issue or the actual process you're processing. also, having logs inside hot-code-path consumes redundant resources (mainly memory)

I removed all the unneeded logs. I only left a couple that are only applying if we cannot parse the property file for any reason. That should not happen so frequently but If I silent it we loose the possibility to understand the cause from the logs. I also tried to remove nesting on some complex functions as highlighted

amarziali avatar Feb 28 '24 16:02 amarziali

/merge

amarziali avatar Mar 06 '24 10:03 amarziali

:steam_locomotive: MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 06 '24 10:03 dd-devflow[bot]

:steam_locomotive: MergeQueue

Added to the queue.

This build is next! (estimated merge in less than 26m)

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 06 '24 10:03 dd-devflow[bot]