Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ treemap*.png
# Claude Code customizations
.claude

# PR review artifacts
.agint-review/
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is added to ignore any review we do with Claude in the repo, since worktrees are created it can become a pain to ensure none of this is considered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit
I've created this standalone PR for this change: #23201
Let's keep the Git history clean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is so minimal that I do not consider this making git history dirty 😅. Also, I needed to add it while working on this since I had so many already that it was imposible to easily parse through the code searching for stuff.

In any case, I approved the other PR and updated this one.


# Ignore any metadata file except root json in the downloader
datadog_checks_downloader/datadog_checks/downloader/data/repo/targets/*
!datadog_checks_downloader/datadog_checks/downloader/data/repo/targets/.gitignore
Expand Down
45 changes: 22 additions & 23 deletions datadog_checks_base/tests/base/utils/db/test_db_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,31 @@ def __run_compute_derivative_rows(self, sm, rounds=10):

def test_compute_derivative_rows_mem_usage(self):
'''
Test that the memory usage of `compute_derivative_rows` is within acceptable limits
Make sure we minimize the temporary objects created when computing the derivative
This test is skipped if tracemalloc is not available
Test that _previous_statements only caches metric columns, not full rows.
This ensures we don't hold on to large non-metric fields (e.g. query text) between check runs.
'''
# The memory usage threshold takes tracing overhead into account
MEMORY_USAGE_THRESHOLD = 10 * 1024 * 1024 # 10 MB

try:
import tracemalloc
except ImportError:
return

tracemalloc.start()

_, peak_before = tracemalloc.get_traced_memory()
sm = StatementMetrics()
self.__run_compute_derivative_rows(sm)

_, peak_after = tracemalloc.get_traced_memory()
tracemalloc.stop()
metrics = ['count', 'time']
rows = [
{
'count': 100,
'time': 2005,
'errors': 1,
'query': 'x' * 3000,
'db': 'puppies',
'user': 'dog',
'query_signature': 'sig{}'.format(random.randint(0, 10000)),
}
for _ in range(10000)
]
sm.compute_derivative_rows(rows, metrics, key=lambda x: x['query_signature'])

# Calculate the difference in memory usage
peak_diff = peak_after - peak_before
assert peak_diff < MEMORY_USAGE_THRESHOLD, "Memory usage difference {} is over the threshold {}".format(
peak_diff, MEMORY_USAGE_THRESHOLD
)
violations = {
key: set(cached_row.keys()) - set(metrics)
for key, cached_row in sm._previous_statements.items()
if not set(cached_row.keys()) <= set(metrics)
}
assert not violations, "Cache contains non-metric columns: {}".format(violations)

def test_compute_derivative_rows_benchmark(self, benchmark):
sm = StatementMetrics()
Expand Down
Loading