Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable obfuscation cache for SQL and MongoDB #31336

Merged
merged 23 commits into from
Nov 26, 2024

Conversation

sethsamuel
Copy link
Contributor

@sethsamuel sethsamuel commented Nov 21, 2024

What does this PR do?

  • Enables a cache for obfuscation of SQL and MongoDB queries.
  • Moves a previously inactive configuration option to the correct place for users to disable this cache if desired.

Motivation

Obfuscating SQL and Mongo queries can incur a substantial CPU overhead, especially of those strings are long. They should be perfectly cacheable, as the obfuscated output should never change given the same input. The query cache was added in a previous change but was not configured correctly.

Enabling the cache on a branch build shows major CPU savings for a Mongo instance:
Screenshot 2024-11-20 at 3 15 06 PM

Describe how to test/QA your changes

Once deployed there should be a drop in CPU usage for agents monitoring databases with large queries.

Possible Drawbacks / Trade-offs

Smoke testing this change on a branch build showed no substantial change in memory usage. The cache is capped at a size that should prevent memory growth.

Additional Notes

Change was deployed to gizmo for testing. Hit rate on the cache is close to 100% very quickly and CPU usage is steady or lower compared to previous RC. Profiling confirms the ObfuscateSQLString method is no longer consuming measurable CPU time.

@github-actions github-actions bot added team/agent-apm trace-agent short review PR is simple enough to be reviewed quickly labels Nov 21, 2024
Copy link

cit-pr-commenter bot commented Nov 21, 2024

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: d097dddd-a26b-4dfe-bf89-ac14bf0b033f

Baseline: 6faf2e3
Comparison: c8ce7d6
Diff

Optimization Goals: ❌ Significant changes detected

perf experiment goal Δ mean % Δ mean % CI trials links
basic_py_check % cpu utilization -5.22 [-9.12, -1.33] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
otel_to_otel_logs ingress throughput +0.81 [+0.12, +1.50] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.07 [-0.71, +0.85] 1 Logs
tcp_syslog_to_blackhole ingress throughput +0.06 [+0.01, +0.12] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.03 [-0.69, +0.74] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.02 [-0.60, +0.65] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.01, +0.01] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.02 [-0.12, +0.08] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.03 [-0.85, +0.79] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.06 [-0.83, +0.71] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput -0.20 [-0.66, +0.27] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization -0.53 [-1.27, +0.20] 1 Logs
pycheck_lots_of_tags % cpu utilization -0.84 [-4.32, +2.63] 1 Logs
quality_gate_idle memory utilization -1.05 [-1.10, -0.99] 1 Logs bounds checks dashboard
file_tree memory utilization -1.51 [-1.65, -1.37] 1 Logs
quality_gate_idle_all_features memory utilization -3.14 [-3.29, -2.98] 1 Logs bounds checks dashboard
basic_py_check % cpu utilization -5.22 [-9.12, -1.33] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard

Explanation

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

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

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".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.

@github-actions github-actions bot added medium review PR review might take time and removed short review PR is simple enough to be reviewed quickly labels Nov 21, 2024
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Nov 21, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv create-vm --pipeline-id=50001871 --os-family=ubuntu

Note: This applies to commit c8ce7d6

@sethsamuel sethsamuel marked this pull request as ready for review November 21, 2024 21:00
@sethsamuel sethsamuel requested review from a team as code owners November 21, 2024 21:00
@sethsamuel sethsamuel requested a review from Kaderinho November 21, 2024 21:00
Copy link
Contributor

@louis-cqrl louis-cqrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@louis-cqrl louis-cqrl removed the request for review from Kaderinho November 22, 2024 10:08
@sethsamuel sethsamuel changed the title Query cache on Enable obfuscation cache for SQL and MongoDB Nov 22, 2024
Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, only a few small comments

@@ -103,6 +103,9 @@ type Config struct {
// Logger specifies the logger to use when outputting messages.
// If unset, no logs will be outputted.
Logger Logger

// Cache enables the query cache for obfuscation for .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this line is unfinished? Maybe it should add SQL and Mongo?

@@ -273,7 +275,10 @@ func (a *Agent) loop() {
a.obfuscator,
a.DebugServer,
} {
stopper.Stop()
// Fun with golang nil checks
if stopper != nil && !reflect.ValueOf(stopper).IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of me thinks this reflection check isn't the ideal place to check this (I do recall the internal chat about this) - since technically there could exist a component that performs valid shutdown logic even on a nil pointer. I'm not super strong feeling here though, so this change isn't necessary for merging here.

pkg/trace/agent/obfuscate.go Show resolved Hide resolved
@ajgajg1134 ajgajg1134 added the qa/done QA done before merge and regressions are covered by tests label Nov 26, 2024
@sethsamuel
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 26, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-26 18:31:59 UTC ℹ️ MergeQueue: waiting for PR to be ready

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.


2024-11-26 19:04:41 UTC ℹ️ MergeQueue: merge request added to the queue

The median merge time in main is 23m.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium review PR review might take time qa/done QA done before merge and regressions are covered by tests team/agent-apm trace-agent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants