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] Support mapping write tags via a header #2255

Merged
merged 15 commits into from
Apr 11, 2020

Conversation

schallert
Copy link
Collaborator

@schallert schallert commented Apr 8, 2020

Implements and closes #2254.

What this PR does / why we need it:

Fixes # 2254

Special notes for your reviewer:

Does this PR introduce a user-facing and/or backwards incompatible change?:

[coordinator] Support rewriting tags on write requests via header

Does this PR require updating code package or user-facing documentation?:


@schallert schallert marked this pull request as ready for review April 8, 2020 02:06
return 0
}

function prometheus_query_native {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be worth pulling these tests into an existing prom remote write test? Then can avoid overhead in setting up the stack

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, it is starting to get copy/pasted into a lot of different places. Unfortunately bash does tend to trend towards this pattern.. at least the way we're writing it/etc since we're not paying a lot of attention/have a lot of experience with DRY bash.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My take though too: would be great if we could actually move this into common.sh.

}

// No existing labels with this tag, append it.
req.Timeseries[i].Labels = append(ts.Labels, prompb.Label{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may need to insert in sorted order

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm @arnikola do we normalize later?

Copy link
Collaborator Author

@schallert schallert Apr 8, 2020

Choose a reason for hiding this comment

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

If we move this to PromLabelsToM3Tags it calls Normalize() at the end

EDIT: Realized this is called after ParseRequest anyway. So we can either allow tags to temporarily be unsorted and wait until they're normalized, or insert in sorted order.

tag := []byte(op.Tag)
value := []byte(op.Value)

TSLoop:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: not sure if we use many labeled continues elsewhere in the codebase, not sure if we want to keep the style choice here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I'd probably opt for a bool then checking the bool after the loop with a break, but yeah - is a nit

return fmt.Errorf("must specify one operation per tag mapper (got %d)", numOps)
}

// AppendOp with value tag="foo" and value="bar" will unconditionally add
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe change the name from append to write or something? Drop and Replace seem to describe their operations well enough, but this is more of an addOrUpdate than an append?


// DropOp with tag="foo" and an empty value will remove all tag-value pairs in
// all timeseries in the write request where the tag was "foo". If value is
// non-empty, a tag-value pair will only be removed if the value was equal to
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe separate op for drop tag vs drop tag with value in the future?

@codecov
Copy link

codecov bot commented Apr 8, 2020

Codecov Report

Merging #2255 into master will decrease coverage by 4.6%.
The diff coverage is 31.9%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #2255     +/-   ##
========================================
- Coverage    71.3%   66.7%   -4.7%     
========================================
  Files        1023    1022      -1     
  Lines       89100   89090     -10     
========================================
- Hits        63574   59456   -4118     
- Misses      21160   25240   +4080     
- Partials     4366    4394     +28
Flag Coverage Δ
#aggregator 69.3% <ø> (-12.8%) ⬇️
#cluster 77.7% <ø> (-7.5%) ⬇️
#collector 82.8% <ø> (ø) ⬆️
#dbnode 76.7% <ø> (+0.5%) ⬆️
#m3em 69.4% <ø> (-5%) ⬇️
#m3ninx 71.6% <ø> (-2.8%) ⬇️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.5% <ø> (ø) ⬆️
#msg 74.8% <ø> (-0.2%) ⬇️
#query 57.8% <31.9%> (-11.6%) ⬇️
#x 71.9% <ø> (-11.4%) ⬇️

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 d4f4931...6370eec. Read the comment docs.

@robskillington robskillington changed the title [query] Support mapping write tags via a header [coordinator] Support mapping write tags via a header Apr 10, 2020
@@ -60,6 +60,10 @@ const (
// in JSON format. See `handler.stringTagOptions` for definitions.`
RestrictByTagsJSONHeader = M3HeaderPrefix + "Restrict-By-Tags-JSON"

// MapTagsByJSONHeader provides the ability to mutate tags of timeseries in
// incoming write requests. See `MapTagsOptions` for structure.
MapTagsByJSONHeader = "M3-Map-Tags-By-JSON"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make this M3HeaderPrefix + "Map-Tags-JSON"? Can we remove the word "By" here? For the restrict it's the term "Restrict-By" then "Tags" then "JSON" this is "Map" then "Tags" then the "By" is before JSON (which is strange).

I think it should probably be "Map-By-Tags-JSON" or just "Map-Tags-JSON".

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 the change to the header name slightly (and also using the M3HeaderPrefix var)

@schallert schallert merged commit 2b9d98f into master Apr 11, 2020
@schallert schallert deleted the schallert/coordinator_write_tags_header branch April 11, 2020 21:57
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.

Support mutating tags on write requests based on headers
3 participants