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

Fix race conditions when running many instances of the Agent #12342

Merged
merged 2 commits into from
Jun 8, 2022

Conversation

justiniso
Copy link
Contributor

@justiniso justiniso commented Jun 7, 2022

What does this PR do?

This removes access to mutable global vars.

Motivation

This is being reported as a bug by customers who are seeing

self._submit_metrics(metrics, results, tags)\\n  File \\\"/opt/datadog-agent/embedded/lib/python3.8/site-packages/datadog_checks/mysql/mysql.py\\\", line 615, in _submit_metrics\\n    for variable, metric in iteritems(variables):\\nRuntimeError: dictionary changed size during iteration\\n\"}]","check":"mysql"}

in the check logs. Basically what is happening is:

  1. We set the metrics global var equal to STATUS_VARS, which is a mutable dict

  2. This is updated at various points in this function

  3. Sometimes these updates are conditional

  4. ... And is iterated over here

  5. There seems to be some kind of race with another instance of the integration? As long as the code path followed every time is the same, no harm, no foul but that isn’t happening here. Making a copy of the dict before updating will prevent this possibility.

Additional Notes

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

@justiniso justiniso requested review from a team as code owners June 7, 2022 16:54
@ghost ghost added the integration/mysql label Jun 7, 2022
@justiniso justiniso marked this pull request as draft June 7, 2022 16:55
@justiniso justiniso marked this pull request as ready for review June 7, 2022 17:06
@justiniso justiniso changed the title Fix bug resulting from metrics changing during iteration Fix race conditions when running many instances of the Agent Jun 7, 2022
@@ -128,12 +128,12 @@ def instance_additional_status():
'disable_generic_tags': 'true',
'additional_status': [
{
'name': "innodb_rows_read",
'name': "Innodb_rows_read",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm trying to figure out why this change is affecting the metrics; that's not clear to me yet, but these values are definitely wrong.

@codecov
Copy link

codecov bot commented Jun 7, 2022

Codecov Report

Merging #12342 (6413a32) into master (8c2d643) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Flag Coverage Δ
mysql 89.01% <100.00%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@justiniso justiniso merged commit d8a8f09 into master Jun 8, 2022
@justiniso justiniso deleted the justindd/mysql-fix-status-vars-global branch June 8, 2022 12:37
github-actions bot pushed a commit that referenced this pull request Jun 8, 2022
* fix STATUS_VARS to avoid using a global var

* fix innodb vars d8a8f09
sarah-witt pushed a commit that referenced this pull request Jun 8, 2022
* fix STATUS_VARS to avoid using a global var

* fix innodb vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants