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

refactor: consistently use one uuid library #40161

Merged
merged 52 commits into from
Sep 9, 2024

Conversation

kruskall
Copy link
Member

@kruskall kruskall commented Jul 10, 2024

Proposed commit message

consistently use one uuid library

the codebase is using a mix of github.com/google/uuid and github.com/gofrs/uuid Update the codebase to use github.com/gofrs/uuid consistently and bump to the current major version.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

the codebase is using a mix of github.com/google/uuid and github.com/gofrs/uuid
Update the codebase to use github.com/gofrs/uuid consistently and bump to the
current major version.
@kruskall kruskall requested review from a team as code owners July 10, 2024 02:01
@kruskall kruskall requested a review from belimawr July 10, 2024 02:01
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 10, 2024
Copy link
Contributor

mergify bot commented Jul 10, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @kruskall? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@kruskall kruskall marked this pull request as draft July 10, 2024 02:08
@efd6
Copy link
Contributor

efd6 commented Jul 10, 2024

Is there a good argument for one over the other? The APIs look pretty similar, but there are some aspects of each that are not in the other, so one is not a drop in replacement for the other.

@kruskall
Copy link
Member Author

Good point!

I don't have a strong opinion on either. To be honest, I went with github.com/gofrs/uuid because that's what we are using in https://github.com/elastic/elastic-agent-system-metrics/

The APIs look pretty similar, but there are some aspects of each that are not in the other, so one is not a drop in replacement for the other.

Can you expand on this ?

@efd6
Copy link
Contributor

efd6 commented Jul 10, 2024

Can you expand on this ?

  • The constructor sets differing is the most obvious thing; there is no gofrs/uuid.New.
  • The errors that are returned are different (I think gofrs is stronger here, but they differ, so use of the error values needs to be checked).
  • There are a few method set differences, so interface satisfaction will differ which may not be noticeable for dynamically asserted interface behaviour.

Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

So far the PR looks great! I don't have any strong preference about which library to use, but I like the fact that github.com/gofrs/uuid is community maintained.

@leehinman
Copy link
Contributor

@kruskall do you think it would be worth it to add the google/uuid to the gomodguard section of .golangci.yml file? That way CI can help us stay with one library.

@kruskall kruskall marked this pull request as ready for review August 1, 2024 23:55
@pierrehilbert pierrehilbert added Team:obs-ds-hosted-services Label for the Observability Hosted Services team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Cloud-Monitoring Label for the Cloud Monitoring team Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Service Integrations Security Service Integrations Team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution labels Aug 5, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Aug 5, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices)

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

It's a pity that this is mixed up with lint clean up.

switch err {
case ErrFileTruncate:
switch {
case errors.Is(err, ErrFileTruncate):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any cases that these error values are returned wrapped so (disclaimer: as a non-owner) I'm not convinced of the value of this, but if this change is going to be made, the tests that look at error values should be updated to match (ErrInactive is the target of an exact value check).

@@ -59,7 +59,7 @@ func NewInputRegistry(inputType, id string, optionalParent *monitoring.Registry)
// logs during support interactions.
log := logp.NewLogger("metric_registry")
// Make an orthogonal ID to allow tracking register/deregister pairs.
uuid := uuid.New().String()
uuid := uuid.Must(uuid.NewV4()).String()
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS crypto/rand.Reader hides EAGAIN so this should be OK.

@kruskall
Copy link
Member Author

kruskall commented Aug 8, 2024

@elastic/beats-tech-leads sorry for the ping, this only need one more review. Any help ? 🙏

Copy link
Contributor

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

A single nit about a check that might have become redundant, but this LGTM

@kruskall kruskall merged commit cd51941 into elastic:main Sep 9, 2024
122 checks passed
@kruskall kruskall deleted the feat/standard-uuid-lib branch September 9, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Team:Cloud-Monitoring Label for the Cloud Monitoring team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:obs-ds-hosted-services Label for the Observability Hosted Services team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Service Integrations Security Service Integrations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.