Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Add StrictMode with event validation #90

Merged
merged 2 commits into from
Aug 12, 2022
Merged

Conversation

rdner
Copy link
Member

@rdner rdner commented Aug 11, 2022

In StrictMode required fields are:

  • Timestamp
  • Datastream.Namespace
  • Datastream.Dataset
  • Datastream.Type
  • Source.InputId

Closes #79

@rdner rdner self-assigned this Aug 11, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Aug 11, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-12T18:57:46.336+0000

  • Duration: 9 min 13 sec

Test stats 🧪

Test Results
Failed 0
Passed 40
Skipped 0
Total 40

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@rdner rdner force-pushed the event-validation branch 2 times, most recently from 1330785 to e5926fc Compare August 12, 2022 11:09
@@ -15,7 +15,7 @@ import (
"github.com/spf13/cobra"

_ "github.com/elastic/elastic-agent-libs/logp/configure"
"github.com/elastic/elastic-agent-shipper/server"
"github.com/elastic/elastic-agent-shipper/controller"
Copy link
Member Author

@rdner rdner Aug 12, 2022

Choose a reason for hiding this comment

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

I moved controller-related stuff to a separate package to resolve the dependency loop with ./config/config.go.

In `StrictMode` required fields are:

* Timestamp
* Datastream.Namespace
* Datastream.Dataset
* Datastream.Type
* Source.InputId
@rdner rdner force-pushed the event-validation branch from e5926fc to b85408e Compare August 12, 2022 11:13
@rdner rdner changed the title Add event validation Add StrictMode with event validation Aug 12, 2022
@rdner rdner marked this pull request as ready for review August 12, 2022 11:28
@rdner rdner requested a review from a team as a code owner August 12, 2022 11:28
@rdner rdner requested review from belimawr and fearful-symmetry and removed request for a team August 12, 2022 11:28
@rdner rdner added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Aug 12, 2022
@rdner rdner requested review from faec and cmacknz August 12, 2022 11:29
Metadata: sampleValues,
Fields: sampleValues,
},
expectedMsg: "timestamp: proto:\u00a0invalid nil Timestamp",
Copy link
Member

Choose a reason for hiding this comment

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

proto:\u00a0invalid

Is the \u00a0 intentional here?

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, this what the gRPC code returns, I had to include it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you could use https://pkg.go.dev/google.golang.org/grpc/status#Convert to convert the error to a status object with both the code and message parsed out to avoid this.

Copy link
Member Author

@rdner rdner Aug 12, 2022

Choose a reason for hiding this comment

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

Ah, you could use https://pkg.go.dev/google.golang.org/grpc/status#Convert to convert the error to a status object with both the code and message parsed out to avoid this.

@cmacknz By code I meant "source code", I don't know why but sometimes it's returned with this character, sometimes it is not. The weird thing is that it does not seem to be flaky when I run tests.

Copy link
Member

@cmacknz cmacknz Aug 12, 2022

Choose a reason for hiding this comment

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

Ah I misinterpreted. Convert or FromError are fine, I missed that it was already used.

The Unicode character is a non-breaking space and it is coming from this code that appears to be deliberately randomizing the returned error string: https://github.com/protocolbuffers/protobuf-go/blob/fb0abd915897428ccfdd6b03b48ad8219751ee54/internal/errors/errors.go#L30

In the timestamppb unit tests they disable the randomization, but the Disable function comes from an internal package: https://github.com/protocolbuffers/protobuf-go/blob/fb0abd915897428ccfdd6b03b48ad8219751ee54/types/known/timestamppb/timestamp_test.go#L22

They also use a wrapper type to avoid direct equality comparisons which might be what we want to do here: https://github.com/protocolbuffers/protobuf-go/blob/fb0abd915897428ccfdd6b03b48ad8219751ee54/types/known/timestamppb/timestamp_test.go#L104

We could also not care about the exact error as long as some error is returned since it is the return value from a method of the timestamppb type we didn't implement ourselves.

All of this seems a bit silly, they are discouraging direct error comparisons but in a highly non-obvious way if I have to read the implementation to figure out what is happening.

Copy link
Member

Choose a reason for hiding this comment

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

The test also seems to pass reliably so this bit of magic in the proto package might not even be doing its job properly in that the error string isn't actually randomized, just unexpected. 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll change the test check in the following PR (which is based on this and in the draft mode for now).

Copy link
Member

Choose a reason for hiding this comment

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

That works, thanks

@rdner rdner requested a review from cmacknz August 12, 2022 15:18
Copy link
Member

@cmacknz cmacknz left a comment

Choose a reason for hiding this comment

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

LGTM, would be nice to parse the returned errors in the tests with https://pkg.go.dev/google.golang.org/grpc/status#Convert but not blocking my approval on that.

@rdner
Copy link
Member Author

rdner commented Aug 12, 2022

/test

@rdner
Copy link
Member Author

rdner commented Aug 12, 2022

@cmacknz

Convert is using FromError (what I use in tests) under the hood, I don't think it's any better.

@rdner
Copy link
Member Author

rdner commented Aug 12, 2022

/test

@rdner
Copy link
Member Author

rdner commented Aug 12, 2022

/test

@rdner rdner merged commit 0faf507 into elastic:main Aug 12, 2022
@rdner rdner deleted the event-validation branch August 12, 2022 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement validation for incoming events
4 participants