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

Add method Fingerprint to data.Labels #712

Merged
merged 3 commits into from
Jul 7, 2023

Conversation

yuri-tceretian
Copy link
Contributor

What this PR does / why we need it:
This PR adds the method Fingerprint to labels that calculates 64-bit FNV-1 hash of the labels.

Which issue(s) this PR fixes:

Related to grafana/grafana#70998

Special notes for your reviewer:

@yuri-tceretian yuri-tceretian added chore go Pull requests that update Go code labels Jul 5, 2023
@yuri-tceretian yuri-tceretian requested a review from a team as a code owner July 5, 2023 13:34
@yuri-tceretian yuri-tceretian self-assigned this Jul 5, 2023
@yuri-tceretian yuri-tceretian requested a review from a team as a code owner July 5, 2023 13:34
@yuri-tceretian yuri-tceretian requested review from marefr and andresmgot and removed request for a team July 5, 2023 13:34
@CLAassistant
Copy link

CLAassistant commented Jul 5, 2023

CLA assistant check
All committers have signed the CLA.

@yuri-tceretian

This comment was marked as outdated.

@sympatheticmoose sympatheticmoose removed the request for review from marefr July 5, 2023 13:56
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Thanks @yuri-tceretian, I have some questions, apart from that adding the rest of the @grafana/plugins-platform-backend as reviewer in case they have more feedback.

@@ -80,6 +81,33 @@ func (l Labels) String() string {
return sb.String()
}

type Fingerprint uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

why the alias?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Few reasons:

  • standard type is too general and may be confusing to read in the code when passed around in user code.
  • simpler to track where the type\value originated.
  • add the possibility to extend the type with methods. For example, Stringer interface.
  • improves maintainability. If we decide to switch from uint64 to byte array or string, less code will need to be rewritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I added String() to represent the hash as a sequence of hex numbers

data/labels.go Show resolved Hide resolved
@andresmgot andresmgot requested review from wbrowne and xnyo July 6, 2023 07:50
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

LGTM! Great work! 🎉 I have left one small optional suggestion

data/labels.go Show resolved Hide resolved
@yuri-tceretian yuri-tceretian merged commit 7e35a1f into main Jul 7, 2023
2 checks passed
@yuri-tceretian yuri-tceretian deleted the yuri-tceretian/labels-hash branch July 7, 2023 13:46
@yuri-tceretian
Copy link
Contributor Author

Thanks, everyone for the review!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore go Pull requests that update Go code
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants