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

Restore default behaviour of returning nil/absent metrics as NaN #1288

Merged

Conversation

nhinds
Copy link
Contributor

@nhinds nhinds commented Jan 30, 2024

The default value for MetricDataResult.Datapoint was 0, so all metrics without datapoints were being returned as if they had a datapoint with the value 0, regardless of the nilToZero flag.

Making this field a pointer allows the v1 and v2 clients to return nil when there is no data, which eventually gets passed through to the existing code for handling nil datapoints and the nilToZero flag.

Fixes #1242

Might be related to #1138

@benbridts
Copy link
Contributor

I tested this to see if it fixes #1138, and it seems like it does:

I am using this config:

---
apiVersion: v1alpha1
discovery:
  jobs:
    - type: AWS/DDoSProtection
      metrics:
        - name: DDoSDetected
          statistics: [ SampleCount ]
      addCloudwatchTimestamp: true
      period: 300
      length: 300
      regions:
        - eu-west-1

    - type: AWS/ApiGateway
      metrics:
        - name: 5XXError
          statistics: [ SampleCount ]
      addCloudwatchTimestamp: true
      period: 300
      length: 300
      regions:
        - eu-west-1

On the master branch, this give me (trimmed for clarity):

aws_apigateway_5_xxerror_sample_count{...} 0 -62135596800000
aws_ddosprotection_ddo_sdetected_sample_count{...} 0 -62135596800000
aws_apigateway_info{...} 0
aws_ddosprotection_info{...} 0

with this branch, I get:

aws_apigateway_info{...} 0
aws_ddosprotection_info{...} 0

which is the same as with previous versions like v0.49.0 and v0.50.0.

If I remove addCloudwatchTimestamp: true, I get on master:

aws_ddosprotection_ddo_sdetected_sample_count{...} 0
aws_apigateway_5_xxerror_sample_count{...} 0
aws_apigateway_info{...} 0
aws_ddosprotection_info{...} 0

and on this branch:

aws_ddosprotection_ddo_sdetected_sample_count{...} NaN
aws_apigateway_5_xxerror_sample_count{...} NaN
aws_apigateway_info{...} 0
aws_ddosprotection_info{...} 0

which is the same as with previous versions like v0.49.0 I also got the NaN behaviour, so this PR looks fine as a fix for #1138 (in previous versions theaws_ddosprotection_ddo_sdetected_sample_count is missing, but that is unrelated to this PR.

@nhinds
Copy link
Contributor Author

nhinds commented Feb 7, 2024

This will be solved differently in #1289, closing

@nhinds nhinds closed this Feb 7, 2024
@nhinds
Copy link
Contributor Author

nhinds commented Feb 9, 2024

Reopening per discussion in #1289 (#1289 (comment)). Will aim to get the bugfix and tests merged and handle the refactor in a later PR.

CC @cristiangreco

@nhinds
Copy link
Contributor Author

nhinds commented Feb 9, 2024

Linting failures seem to be new between golangci-lint 1.56.0 and 1.56.1 - docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.56.0 golangci-lint run -v succeeds, while docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.56.1 golangci-lint run -v fails. The same code also passed linting 2 weeks ago on version 1.55.2 (https://github.com/nerdswords/yet-another-cloudwatch-exporter/actions/runs/7705664092/job/20999963536). I assume the CI is floating on the latest version of golangci-lint as I don't see any commits that would bump this.

The failures seem to be in files I haven't touched (pkg/clients/tagging/*, pkg/clients/v1/*, pkg/job/compact_test.go, cmd/yace/*)

@cristiangreco
Copy link
Contributor

The failures seem to be in files I haven't touched (pkg/clients/tagging/*, pkg/clients/v1/*, pkg/job/compact_test.go, cmd/yace/*)

Can you please rebase? The linter errors have been fixed in #1295

The `$` in the Makefile was being interpreted by `make`, and running the
incorrect command `go test -v -bench=^-race -count=1 ./...`
Copy link
Contributor

@cristiangreco cristiangreco left a comment

Choose a reason for hiding this comment

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

LGTM, left just some comments around tests.

pkg/clients/cloudwatch/v2/client_test.go Outdated Show resolved Hide resolved
pkg/clients/cloudwatch/v2/client_test.go Outdated Show resolved Hide resolved
pkg/clients/cloudwatch/v1/client_test.go Show resolved Hide resolved
The default value for MetricDataResult.Datapoint was 0, so all
metrics without datapoints were being returned as if they had
a datapoint with the value 0, regardless of the nilToZero flag.

Making this field a pointer allows the v1 and v2 clients to return
nil when there is no data.
Copy link
Contributor

@cristiangreco cristiangreco left a comment

Choose a reason for hiding this comment

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

Great work! 🚀

@cristiangreco cristiangreco merged commit 340e810 into prometheus-community:master Feb 14, 2024
3 checks passed
TanZng pushed a commit to grid-x/yet-another-cloudwatch-exporter that referenced this pull request Feb 14, 2024
TanZng pushed a commit to grid-x/yet-another-cloudwatch-exporter that referenced this pull request Feb 14, 2024
TanZng added a commit to grid-x/yet-another-cloudwatch-exporter that referenced this pull request Feb 21, 2024
* Bump github.com/aws/aws-sdk-go from 1.49.16 to 1.49.17 (prometheus-community#1267)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add IPAM metrics support (prometheus-community#1168)

Co-authored-by: Cristian Greco <[email protected]>

* Bump github.com/aws/aws-sdk-go from 1.49.17 to 1.49.19 (prometheus-community#1275)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump the aws-sdk-v2 group with 1 update (prometheus-community#1274)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Prepare changelog for v0.56.0 (prometheus-community#1273)

* Bump github.com/aws/aws-sdk-go from 1.49.19 to 1.49.21 (prometheus-community#1277)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/prometheus/common from 0.45.0 to 0.46.0 (prometheus-community#1276)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Optionally include context labels (account, region, customTags) on info metrics (prometheus-community#1249)

Co-authored-by: Cristian Greco <[email protected]>

* Simplify associator usage (prometheus-community#1280)

Co-authored-by: Cristian Greco <[email protected]>

* Fix race condition in scraper registry usage (prometheus-community#1281)

* Refactor dimensions regexp usage for discovery jobs (prometheus-community#1279)

* Bump the aws-sdk-v2 group with 1 update (prometheus-community#1282)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Bump github.com/aws/aws-sdk-go from 1.49.21 to 1.50.0 (prometheus-community#1283)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Improve usability and performance of searchTags (prometheus-community#1270)

Co-authored-by: Cristian Greco <[email protected]>

* Fix lint issues for golangci-lint 1.56.1 (prometheus-community#1295)

* Bump alpine from 3.19.0 to 3.19.1 (prometheus-community#1287)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Add serverless ElastiCache support (prometheus-community#1254)

Co-authored-by: Cristian Greco <[email protected]>

* Fix elasticache serverless test after merge (prometheus-community#1299)

* Restore default behaviour of returning nil/absent metrics as NaN (prometheus-community#1288)

Co-authored-by: Cristian Greco <[email protected]>

* Bump the aws-sdk-v2 group with 5 updates (prometheus-community#1297)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Bump github.com/aws/aws-sdk-go from 1.50.0 to 1.50.10 (prometheus-community#1291)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cristian Greco <[email protected]>

* Update build tools and CI to go 1.22 (prometheus-community#1301)

* chore: update version

* chore: update test to support historical data

* chore: fix return

* chore: fix git missing for test

* chore: cgo for test

* chore: don't use cgo

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: pkubicsek-sb <[email protected]>
Co-authored-by: Cristian Greco <[email protected]>
Co-authored-by: kgeckhart <[email protected]>
Co-authored-by: Nicholas Hinds <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] RDS metrics - values for non-existant DatabaseClass show up
3 participants