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

Prevent hostname evaluating to None in sqlserver check #18237

Merged
merged 6 commits into from
Oct 28, 2024

Conversation

jmeunier28
Copy link
Contributor

@jmeunier28 jmeunier28 commented Aug 7, 2024

What does this PR do?

This change prevents a very bad bug where the host field on metrics and events will fall back to None when the static information cache reaches its TTL of 1 day. When this happens, we see gaps in data for sqlserver instances because our backend drops these as bad payloads. We can see an example of this happening in our integration environment:

Screenshot 2024-08-07 at 1 11 00 PM

... meanwhile, if we log the payloads we see the host value is set to null:

{"host":null,"ddagentversion":"7.56.0","ddsource":"sqlserver",...

Motivation

https://datadoghq.atlassian.net/browse/DBMON-4711

In this previous change #17750 we updated the check to call

    def check(self, _):
        if self.do_check:
            self.load_static_information()

on each check run. This function does a few things:

  1. Checks to see we are missing key/value pairs in our static information cache
  2. re-loads the cache if this is the case
  3. if keys are missing, it also resets the self._resolved_hostname value to None, but it never initializes the value

This makes the load_static_information not safe to call outside of the context of the set_resolved_hostname function. In order to prevent the resolved_hostname property from ever returning None we add a null check && re-initialize the value if necessary:

        if self._resolved_hostname is None:
             self.set_resolved_hostname()
        return self._resolved_hostname

Additional Notes

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Changelog entries must be created for modifications to shipped code
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

ynnadkrap
ynnadkrap previously approved these changes Aug 7, 2024
ynnadkrap
ynnadkrap previously approved these changes Aug 7, 2024
lu-zhengda
lu-zhengda previously approved these changes Aug 7, 2024
ofek
ofek previously approved these changes Aug 7, 2024
Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

After merging, can we please add a test?

@jmeunier28
Copy link
Contributor Author

merged this one instead #18249 so i can deal with the tests separately. I cannot easily run the tests / fix them tonight and this is blocking the agent release

@lu-zhengda lu-zhengda requested a review from a team October 24, 2024 19:22
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@2b35698). Learn more about missing BASE report.
Report is 10 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
sqlserver 91.08% <100.00%> (?)

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

@nenadnoveljic
Copy link
Contributor

nenadnoveljic commented Oct 28, 2024

Can you link to the Jira card?

@lu-zhengda lu-zhengda added this pull request to the merge queue Oct 28, 2024
Merged via the queue into master with commit e50672b Oct 28, 2024
44 checks passed
@lu-zhengda lu-zhengda deleted the jmeunier/bug-fix-resolved-host branch October 28, 2024 15:19
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.

7 participants