opentelemetry-collector-contrib icon indicating copy to clipboard operation
opentelemetry-collector-contrib copied to clipboard

[exporter/prometheusremotewriteexporter] Fix a go panic

Open falken opened this issue 3 years ago • 10 comments

Description: Protect against a Go Panic when the bucket count collection is empty (observed with histograms coming from Micrometer 1.9.1

Fixes #12168 #12168

falken avatar Jul 07 '22 18:07 falken

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: falken / name: Steven Nelson (29f4688b278229f72cfd46b17d8b366b525521dd)

Thanks for the fix! Please add a changelog entry https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#changelog

Added, hopefully correctly

falken avatar Jul 07 '22 19:07 falken

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: falken / name: Steven Nelson (ac91e26958ae7e91fbf1d250158633f8e7bd389d)

Okay, @MovieStoreGuy I have added a test, and verified that the fix works, however I can't figure out what's wrong with the assertion.

I get:

helper_test.go:668:
            Error Trace:    /mnt/c/bench/dev/falken/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite/helper_test.go:668
            Error:          Not equal:
                            expected: map[string]*prompb.TimeSeries{"Histogram-__name__-foo_valid_Histogram_bucket-le-+Inf":(*prompb.TimeSeries)(0xc00028ea80), "Histogram-__name__-foo_valid_Histogram_count":(*prompb.TimeSeries)(0xc00028eaf0), "Histogram-__name__-foo_valid_Histogram_sum":(*prompb.TimeSeries)(0xc00028eb60)}
                            actual  : map[string]*prompb.TimeSeries{"Histogram-__name__-foo_valid_Histogram_bucket-le-+Inf":(*prompb.TimeSeries)(0xc00028ecb0), "Histogram-__name__-foo_valid_Histogram_count":(*prompb.TimeSeries)(0xc00028ec40), "Histogram-__name__-foo_valid_Histogram_sum":(*prompb.TimeSeries)(0xc00028ebd0)}

                            Diff:
            Test:           Test_addSingleHistogramDataPoint/histogram_without_buckets

--- FAIL: Test_addSingleHistogramDataPoint (0.00s) --- FAIL: Test_addSingleHistogramDataPoint/histogram_without_buckets (0.00s)

falken avatar Jul 08 '22 21:07 falken

I think you want to use assert.EqualValues instead of assert.Exactly since I suspect it is trying to enforce the same pointer address.

MovieStoreGuy avatar Jul 11 '22 02:07 MovieStoreGuy

I think you want to use assert.EqualValues instead of assert.Exactly since I suspect it is trying to enforce the same pointer address.

Both Exactly and EqualValues eventually use reflect.DeepEquals, which apparently returns false for the two maps.

falken avatar Jul 11 '22 15:07 falken

@MovieStoreGuy Found the problem. Because the +Inf bucket has a value of NaN I can't compare them because NaN == NaN is false. I made the test explicitly test this case which should work.

falken avatar Jul 11 '22 16:07 falken

@MovieStoreGuy Found the problem. Because the +Inf bucket has a value of NaN I can't compare them because NaN == NaN is false. I made the test explicitly test this case which should work.

I am glad you saw that because I did not.

Thank you for taking the time to fix this.

MovieStoreGuy avatar Jul 11 '22 23:07 MovieStoreGuy

This PR was marked stale due to lack of activity. It will be closed in 14 days.

github-actions[bot] avatar Jul 27 '22 05:07 github-actions[bot]

Apparently this is moot @Aneurysm9 @MovieStoreGuy since PR #12854

falken avatar Aug 04 '22 15:08 falken

This PR was marked stale due to lack of activity. It will be closed in 14 days.

github-actions[bot] avatar Aug 19 '22 05:08 github-actions[bot]

Closed as inactive. Feel free to reopen if this PR is still being worked on.

github-actions[bot] avatar Sep 15 '22 05:09 github-actions[bot]