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

receiver/prometheus/internal: add createNodeAndResourcePdata for Prometheus->OTLP Pdata #3139

Conversation

odeke-em
Copy link
Member

Starts the progressive effort to convert directly from
Prometheus->OTLPPdata

directly instead of

Prometheus->OpenCensusProto->OTLPPdata

by adding a converter for node+resource -> pdata.Resource.

Updates #3137

@odeke-em odeke-em requested a review from a team May 11, 2021 01:38
@odeke-em odeke-em force-pushed the receiver-prometheus-createNodeAndResource branch from bbe1e0b to b949055 Compare May 11, 2021 01:39
@odeke-em
Copy link
Member Author

Kindly cc-ing @alolita @Aneurysm9 @rakyll @bogdandrutu; there is a long chain of PRs coming to progressively make equivalent converters and have full tests and then when ready just switch over entirely when we have complete converters.

@alolita
Copy link
Member

alolita commented May 11, 2021

@anuraaga @Aneurysm9 @rakyll can you please review?

Comment on lines 53 to 55
if diff := cmp.Diff(byDirectOTLPResource, fromOCResource, protocmp.Transform()); diff != "" {
t.Fatalf("Resource mismatch: got: - want: +\n%s", diff)
}
Copy link
Member

Choose a reason for hiding this comment

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

You have sort on the AttributeMap, so you can sort both resources. Also we try to avoid using cmp.Diff and encourage github.com/stretchr/testify to be used.

Copy link
Contributor

@anuraaga anuraaga May 12, 2021

Choose a reason for hiding this comment

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

I don't think we need this comparison test, just write assertions on the PData as you normally would, verifying its structure. The OC code is going to get deleted at which point these tests will need to be rewritten anyways, we should do it now. I believe all the current caveats in the PR would go away if doing so.

func TestCreateNodeAndResourceConversion(t *testing.T) {
job, instance, scheme := "converter", "ocmetrics", "http"
ocNode, ocResource := createNodeAndResource(job, instance, scheme)
mdFromOC := internaldata.OCToMetrics(internaldata.MetricsData{
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid using deprecated methods, and deprecated OC format even in tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I am doing a straight up translation of what exists in the code and I need to produce the exact same result that the current code produces. This PR converts from Prometheus->OTLP instead of Prometheus->OpenCensus->OTLP, and once the entire translation is done and we are sure that we have an absolute 1-to-1 mapping, these tests will be discarded.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the test can be renamed in a way that makes it clear it is only intended to validate congruence with the outgoing implementation and will need to be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good @Aneurysm9, I've renamed it to TestCreateNodeAndResourceEquivalence

}
resource := pdata.NewResource()
attrs := resource.Attributes()
attrs.UpsertString(conventions.AttributeServiceName, job)
Copy link
Contributor

Choose a reason for hiding this comment

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

@alolita Does anyone own the spec for prometheus mapping of the standard conventions? These seem somewhat arbitrary. If they can be excluded, I'd only add the prometheus specific attributes for now

Copy link
Member Author

Choose a reason for hiding this comment

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

@anuraaga this is a straight up translation of what already exists in the current converter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know - it doesn't block this PR but someone needs to be working on that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool!

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to open an issue to track this.

Choose a reason for hiding this comment

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

Maybe we need to open an issue to track this.

Why upsert the job to service.name? Shouldn't it be better to check if service.name has been set?

Comment on lines 53 to 55
if diff := cmp.Diff(byDirectOTLPResource, fromOCResource, protocmp.Transform()); diff != "" {
t.Fatalf("Resource mismatch: got: - want: +\n%s", diff)
}
Copy link
Contributor

@anuraaga anuraaga May 12, 2021

Choose a reason for hiding this comment

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

I don't think we need this comparison test, just write assertions on the PData as you normally would, verifying its structure. The OC code is going to get deleted at which point these tests will need to be rewritten anyways, we should do it now. I believe all the current caveats in the PR would go away if doing so.

@odeke-em
Copy link
Member Author

@bogdandrutu @tigrannajaryan kind ping!

@anuraaga
Copy link
Contributor

My comment about adding normal unit tests, not just parity ones, seems to still not be addressed

@odeke-em odeke-em force-pushed the receiver-prometheus-createNodeAndResource branch from 9e0df1b to 33919a8 Compare May 14, 2021 03:31
@odeke-em
Copy link
Member Author

My comment about adding normal unit tests, not just parity ones, seems to still not be addressed

@anuraaga thanks, I hadn't seen your comment, but I've just answered by saying that for the very beginning let's focus on full equivalence which is currently the uphill task.

@anuraaga
Copy link
Contributor

@odeke-em Having the parity tests is fine - but this is new code. As with any new code, we add test cases and assertions for them. We'll have to do it anyways to remove the opencensus APIs which we really want to do, so we should do it now.

@bogdandrutu
Copy link
Member

@odeke-em Having the parity tests is fine - but this is new code. As with any new code, we add test cases and assertions for them. We'll have to do it anyways to remove the opencensus APIs which we really want to do, so we should do it now.

I completely agree, also the parity tests will be removed when we switch to the new code so we will be left without unit-tests.

@alolita
Copy link
Member

alolita commented May 14, 2021

@odeke-em can you please address @anuraaga and @bogdandrutu for adding tests cases and assertions so that this PR can be merged. ty!

@bogdandrutu bogdandrutu dismissed tigrannajaryan’s stale review May 17, 2021 16:14

The main blocking change was fixed

@odeke-em
Copy link
Member Author

I completely agree, also the parity tests will be removed when we switch to the new code so we will be left without unit-tests.

Sure, I am going to add them but I predict that the amount of review time is going to be increase even more, which was the entire point of firstly mailing parity tests, then later on unit tests.

@bogdandrutu
Copy link
Member

Waiting for the author to add unit-tests.

@github-actions
Copy link
Contributor

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 May 27, 2021
…etheus->OTLP Pdata

Starts the progressive effort to convert directly from
    Prometheus->OTLPPdata

directly instead of

    Prometheus->OpenCensusProto->OTLPPdata

by adding a converter for node+resource -> pdata.Resource.

Updates #3137
Addresses feedback pointed out by Bogdan, Tigran, Jaana
by using Resource.Attributes().Sort() instead and also avoid
using go-cmp/cmp and instead opt to using require.Equal.
@odeke-em odeke-em force-pushed the receiver-prometheus-createNodeAndResource branch from 33919a8 to 6ea4b9e Compare May 27, 2021 08:17
@odeke-em odeke-em requested a review from alolita as a code owner May 27, 2021 08:17
@odeke-em
Copy link
Member Author

@bogdandrutu @anuraaga please take a look.

@github-actions github-actions bot removed the Stale label May 28, 2021
@odeke-em
Copy link
Member Author

odeke-em commented Jun 2, 2021

Kind ping @bogdandrutu..

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.

10 participants