DataDog / integrations-core

Core integrations of the Datadog Agent
BSD 3-Clause "New" or "Revised" License
937 stars 1.41k forks source link

[Backport 7.59.x] [postgres] Fix unicode decode error from Azure PostgreSQL Flexible Server #18949

Closed datadog-agent-integrations-bot[bot] closed 2 weeks ago

datadog-agent-integrations-bot[bot] commented 2 weeks ago

Backport 3d527cab62aa44313d690f64b8ee569ed1f0dc7f from #18938.


What does this PR do?

This PR fixes the bug encountered in Azure PostgreSQL Flexible Server in the backend_type column of pg_stat_activity.

There is a bug on Microsoft's side where they send a non valid utf-8 string in that column, leading to decoding errors when trying to fetch this column.

The workaround is to query that same column with ::byteasuffix to convert the field into bytes then parsing backend_type manually. The bug still exists but now we just handle those error cases instead of failing on the whole query.

Motivation

https://datadoghq.atlassian.net/browse/SDBM-1169 https://datadoghq.atlassian.net/browse/SDBM-1197

incident-31599

A couple of customers where seeing errors utilizing DBM with Azure PG Flexible Server when agent tries to query backend_type from pg_stat_activity. We previously issued a fix but had to revert due to many warnings being logged from the agent.

Review checklist (to be filled by reviewers)

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (7.59.x@cff91ad). Learn more about missing BASE report.

Additional details and impacted files | [Flag](https://app.codecov.io/gh/DataDog/integrations-core/pull/18949/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | Coverage Δ | | |---|---|---| | [postgres](https://app.codecov.io/gh/DataDog/integrations-core/pull/18949/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `93.27% <77.77%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#carryforward-flags-in-the-pull-request-comment) to find out more.