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

contrib/iinternal/coreinternal: add helpers for Pdata Metrics #5231

Conversation

odeke-em
Copy link
Member

Adds helper functions to help create metrics for OTLP
pdata translations. The need for these helpers comes
from PR #5184 in which we need to translate directly
from Prometheus->Pdata instead of Prometheus->OpenCensus->Pdata,
but we shall need to modify both receiver/prometheus*/internal and
the base directory.

This code is heavily used in the mentioned PR and thus no
tests included in this change.

Updates PR #5184

Adds helper functions to help create metrics for OTLP
pdata translations. The need for these helpers comes
from PR #5184 in which we need to translate directly
from Prometheus->Pdata instead of Prometheus->OpenCensus->Pdata,
but we shall need to modify both receiver/prometheus*/internal and
the base directory.

This code is heavily used in the mentioned PR and thus no
tests included in this change.

Updates PR #5184
@odeke-em odeke-em requested review from a team and djaglowski September 13, 2021 23:05
@odeke-em
Copy link
Member Author

Kindly help me with a blind review/approval here @dashpole @alolita @bogdandrutu @Aneurysm9 @codeboten as this code is used in the linked PR.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

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

To help show the value of this, can I kindly ask you to add tests to this?

@odeke-em
Copy link
Member Author

To help show the value of this, can I kindly ask you to add tests to this?

In the PR subject I explain its purpose and particularly

This code is heavily used in the mentioned PR and thus no
tests included in this change.

@MovieStoreGuy
Copy link
Contributor

If the code is heavily used in the mentioned PR then it should be tested here. Having heavily used code is not an excuse to not write tests.

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

Consider to make this internal to the module that needs it for the moment.

Key, Value string
}

func DistPointPdata(ts pdata.Timestamp, bounds []float64, counts []uint64) *pdata.HistogramDataPoint {
Copy link
Member

Choose a reason for hiding this comment

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

Do not return pointer to pdata.

Key, Value string
}

func DistPointPdata(ts pdata.Timestamp, bounds []float64, counts []uint64) *pdata.HistogramDataPoint {
Copy link
Member

Choose a reason for hiding this comment

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

pdata usually benefits more if instead of constructing new Metric, you append it to a MetricSlice. Less allocations.

@bogdandrutu
Copy link
Member

Also +1 to @MovieStoreGuy comment about having tests.

@odeke-em
Copy link
Member Author

If the code is heavily used in the mentioned PR then it should be tested here. Having heavily used code is not an excuse to not write tests.

I appreciate the enthusiasm and time to review @MovieStoreGuy and @bogdandrutu,. but this doesn't make sense to me, and seems like it is just being pedantic without context about what's happening. This code doesn't add new core code functionality. There is nothing unique about me just copying and pasting this code allover, this isn't code for pdata construction in our libraries, this would be literal helpers in my test code. It costs me much less time to just duplicate this functionality which doesn't add any surface area except in building points effectively. With that logic, all the test helpers should also be tested -- this doesn't hold up for any library, and doesn't add value for the end goals for which these libraries are already years behind in ditching OpenCensus.

@MovieStoreGuy
Copy link
Contributor

@odeke-em , the point of adding tests and smaller PRs is that things can be reviewed in isolation and build up to the larger context as (more bottom up than top down). It helps keeps things streamed line and the community can review with confidence.

This code doesn't add new core code functionality.

From what I can tell with this git commit, it is for the project.

this would be literal helpers in my test code

Aa, I had missed that, my apologies. It wasn't clear these methods were to be only used for tests purposes since the title of the PR and the method names themselves didn't help allude to that fact.

Can I ask that you comment to that affect? Making it clear that these methods are to be used for testing purposes only?

@anuraaga
Copy link
Contributor

With that logic, all the test helpers should also be tested

The reality is this is generally considered good practice - test helpers combine to become a test framework basically. Then we need to catch issues that affect the framework in the framework itself. For example, perhaps some refactoring affects AppendEmpty and breaks this logic - failures showing up with longer stack traces deep in unrelated code will make it very difficult to update this file. In fact, if the same logic was instead copied into five places, at least it's obvious that those five places need to be updated, instead of five unrelated places that you then have to navigate back to here. This is precisely the motivation for unit tests in software engineering.

This code isn't in _test.go files - it's unfortunate that we still haven't reenabled codecov since their security incident since it's great for verifying how we're doing. But the intent is to have a code coverage threshold - if the check was reenabled, this PR wouldn't even be mergable since it wouldn't pass the codecov threshold (applied since it's not _test.go).

They're simple functions and can use just some simple tests so it'd be great if you can add them. I appreciate that it is annoying to write tests - but let's just write them and move on :)

@bogdandrutu
Copy link
Member

bogdandrutu commented Sep 15, 2021

@anuraaga as suggested:

  1. This code should leave in an internal directory for the module that uses it until clear reason to share (even if this is called internalcore it is still shared).
  2. The package name can be named "testmetricsutil" or something that suggest to be a testing package.
  3. Usually I have test for testing packages as well see https://github.com/open-telemetry/opentelemetry-collector/tree/main/component/componenttest, but I would not enforce that if this is internal only for that module, and marked accordingly as testing package.

odeke-em referenced this pull request in orijtech/opentelemetry-collector-contrib Sep 21, 2021
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2021

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

@github-actions github-actions bot added the Stale label Oct 6, 2021
@bogdandrutu bogdandrutu removed the Stale label Oct 6, 2021
@github-actions
Copy link
Contributor

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

@bogdandrutu
Copy link
Member

Closing this PR as inactive, since the feedback was not addressed for more than 1m.

bogdandrutu pushed a commit that referenced this pull request Dec 8, 2021
* receiver/prometheus: roundtrip Prometheus->Pdata direct conversion without OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695

* Retrofit top level package for pdata comparisons

* Reuse for pdata metrics creators from PR #5231

* Shed all in-code direct references to OpenCensus

* receiver/prometheus: fix tests

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: buffer metrics in builder to avoid issues with out-of-order exposition

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: restore prom->OC->pdata pipeline

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: add feature gate to control whether to use OpenCensus or pdata directly

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: localize metrics test helpers

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: store metrics in a map in metricbuilder to avoid issues with out-of-order exposition data

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: run component tests against both OC and pdata export paths

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: ensure OC metrics builder tests are deterministic

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: restore replace directive to ensure use of local copy of opencensus translator during development

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: fix lint issues

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: fix lint issues

Signed-off-by: Anthony J Mirabella <[email protected]>

* make porto

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: run e2e tests in parallel to avoid doubling test suite runtime

Signed-off-by: Anthony J Mirabella <[email protected]>

* Revert "receiver/prometheus: run e2e tests in parallel to avoid doubling test suite runtime"

This reverts commit 7e04b44.

* receiver/prometheus: address PR feedback

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: ensure test helper can extract timestamp from metrics of any type

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: tests should not be expecting empty label values

Signed-off-by: Anthony J Mirabella <[email protected]>

* make porto

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: remove gauge histogram pdata adjustment tests

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: remove unused gauge histogram data generator helper

Signed-off-by: Anthony J Mirabella <[email protected]>

* Fix lint errors

Signed-off-by: Anthony J Mirabella <[email protected]>

* receiver/prometheus: Add comments detailing use of locks in metrics adjuster.

Signed-off-by: Anthony J Mirabella <[email protected]>

Co-authored-by: Emmanuel T Odeke <[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.

5 participants