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

[coordinator] Treat Prometheus TagName/Value as []byte instead of String #1004

Merged
merged 6 commits into from
Oct 3, 2018

Conversation

arnikola
Copy link
Collaborator

@arnikola arnikola commented Oct 2, 2018

Change tag names and values from strings to []bytes

@@ -91,5 +92,6 @@ func TestAndWithSomeValues(t *testing.T) {
expected := values1
expected[0][1] = math.NaN()
expected[1][0] = math.NaN()
fmt.Println(expected, sink.Values)
Copy link
Collaborator

Choose a reason for hiding this comment

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

need to remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops yeah made a mental note to clean these but forgot it unfortunately

@prateek prateek changed the title Arnikola/prom proto bytes [coordinator] Treat Prometheus TagName/Value as []byte instead of String Oct 2, 2018
@@ -120,11 +120,11 @@ func (w *downsamplerFlushHandlerWriter) Write(
tags := make(models.Tags, 0, expected+1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: This should actually just be expected not expected+1 since we increment expected above if there is an aggregation tag.

@@ -90,8 +90,13 @@ func newStorageWriteQuery(req *WriteQuery) (*storage.WriteQuery, error) {
return nil, err
}

tags := models.Tags{}
Copy link
Collaborator

@robskillington robskillington Oct 2, 2018

Choose a reason for hiding this comment

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

nit: Could preallocate the size here, make(models.Tags, 0, len(req.Tags))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah good call, wasn't overly concerned with the perf here since it's kind of a test endpoint but will make the change :)

Name string `json:"name"`
Value string `json:"value"`
Name []byte `json:"name"`
Value []byte `json:"value"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a warning, the JSON serializer will now encode these as base64:
https://play.golang.org/p/T3Xa8OGyWML

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do matchers also need to be bytes? These only come through for reads yeah?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, these are only needed for reads, but figured may as well convert them to bytes; would the base64 be a problem? We only really use it for sending to the session or encode them to []byte anyway on remote fetches

}

return m
return []byte{}, false
Copy link
Collaborator

Choose a reason for hiding this comment

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

return nil, false is slightly more optimal (no allocs)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call

identTags = append(identTags, ident.StringTag(t.Name, t.Value))
n := checked.NewBytes(t.Name, checked.NewBytesOptions())
v := checked.NewBytes(t.Value, checked.NewBytesOptions())
identTags = append(identTags, ident.BinaryTag(n, v))
Copy link
Collaborator

Choose a reason for hiding this comment

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

For now, perhaps we should replace with just a zero copy version (since models.Tags should be coming from the wire and won't be mutated?):

identTags := make([]ident.Tag, 0, len(tags))
for _, t := range tags {
  identTags = append(identTags, ident.Tag{Name: ident.BytesID(t.Name), Value: ident.BytesID(t.Value)})
}
return ident.NewTagsIterator(ident.NewTags(identTags...)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh nice, don't know why I missed the ident.Bytes; was probably looking for something like ident.ByteTag or something :p

@codecov
Copy link

codecov bot commented Oct 2, 2018

Codecov Report

Merging #1004 into master will increase coverage by 0.07%.
The diff coverage is 94.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
+ Coverage   77.59%   77.67%   +0.07%     
==========================================
  Files         412      412              
  Lines       34697    34705       +8     
==========================================
+ Hits        26923    26956      +33     
+ Misses       5903     5880      -23     
+ Partials     1871     1869       -2
Flag Coverage Δ
#dbnode 81.52% <ø> (+0.03%) ⬆️
#m3ninx 75.33% <ø> (+0.07%) ⬆️
#query 63.32% <94.04%> (+0.24%) ⬆️
#x 84.72% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1891c7...17d32da. Read the comment docs.

@@ -64,10 +64,13 @@ func FromIdentTagIteratorToTags(identTags ident.TagIterator) (models.Tags, error

// TagsToIdentTagIterator converts coordinator tags to ident tags
func TagsToIdentTagIterator(tags models.Tags) ident.TagIterator {
//TODO get a checked bytes pool here instead
Copy link
Collaborator

@robskillington robskillington Oct 3, 2018

Choose a reason for hiding this comment

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

nit: Maybe update this to what remains here now that we are using ident.BytesID:
// TODO get a Tags and TagsIterator from a ident.Pool here instead of allocing them here

Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

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

LGTM other than last nit, it'd be great to test this on the GCP VMs to see what the improvement looks like 😄

@arnikola arnikola merged commit 72463c7 into master Oct 3, 2018
@arnikola arnikola deleted the arnikola/prom-proto-bytes branch October 3, 2018 16:58
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.

3 participants