Add support for tag metadata.#1032
Add support for tag metadata.#1032rghetia wants to merge 11 commits intocensus-instrumentation:masterfrom
Conversation
|
This should be merged only after the spec pr is merged. |
songy23
left a comment
There was a problem hiding this comment.
Is this ready for review?
tag/map.go
Outdated
| // doesn't exist already. It mutates the value and the | ||
| // Metadata if k already exists. | ||
| // If metadata md is nil then it defaults to NonPropagatingMetadata | ||
| func UpsertWithMetadata(k Key, v string, md *Metadata) Mutator { |
There was a problem hiding this comment.
Maybe consider to use the same pattern as StartOption from StartSpan in trace.
type metadatas struct {
ttl int
}
type Metadata func(*metadatas)
// Not exported for the moment because we want only TTLNoPropagation and TTLUnlimitedPropagation
func withTTL(ttl int) Metadata {
return func(*metadatas) {
}
}
var (
TTLNoPropagation = withTTL(valueTTLNoPropagation)
TTLUnlimitedPropagation = withTTL(valueTTLUnlimitedPropagation)
}
func Upsert(k Key, v string, mds ...Metadata) Mutator {
metas metadatas
for _, md := range mds {
op(&metas)
}
}Users will use this:
tag.Upsert(key, "my_value", TTLNoPropagation, other_metadata)What do you think? @rakyll do you have any suggestion?
tag/map.go
Outdated
| } | ||
|
|
||
| func (m *Map) insert(k Key, v string) { | ||
| func (m *Map) insert(k Key, v string, md *Metadata) { |
There was a problem hiding this comment.
Why pointer to metadata?
There was a problem hiding this comment.
metadata may or may not exists or given kv pair. Also metadata could be reused for several kv pair, In that case it can be reused.
tag/map.go
Outdated
| } | ||
| } | ||
|
|
||
| // UpsertWithMetadata returns a mutator that upserts the |
There was a problem hiding this comment.
UpsertWithMetadata is a very verbose name for a core API.
Please consider short names. If not, user will never think about UpsertWithMetadata is a replacement for Upsert.
|
@bogdandrutu, @songy23 PTAL. |
tag/metadata.go
Outdated
| var ( | ||
| // TTLNoPropagation applies metadata with ttl value of valueTTLNoPropagation. | ||
| // It is predefined for convenience. | ||
| TTLNoPropagation = withTTL(valueTTLNoPropagation) |
There was a problem hiding this comment.
Not sure if we want to expose these constants here. See the comment at census-instrumentation/opencensus-java#1768 (comment).
There was a problem hiding this comment.
The intention was to restrict from using any value other than two TTL values. But this is not the right approach as TTLNoPropation can be modified by the user. Let me look at how to do this differently.
| } | ||
|
|
||
| // Metadata applies metadatas specified by the function. | ||
| type Metadata func(*metadatas) |
There was a problem hiding this comment.
Curious why this needs to be func?
There was a problem hiding this comment.
sort of like a builder (similar to startOption for startSpan).
tag/metadata.go
Outdated
|
|
||
| // WithTTLNoPropagation applies metadata with ttl value of valueTTLNoPropagation. | ||
| // It is predefined for convenience. | ||
| func WithTTLNoPropagation() Metadata { |
There was a problem hiding this comment.
What do you think about this?
type TTL struct {
value int
}
var (
NoPropagation = &TTL{value= 0}
UnlimitedPropagation = &TTL{value= -1}
)
func WithTTL(TTL ttl) Metadata {
return func(m *metadatas) {
m.ttl = ttl
}
}
There was a problem hiding this comment.
you could inadvertently modify UnlimitedPropagation and WithTTL would allow any value of TTL. I thought we don't want that at this point
There was a problem hiding this comment.
@rakyll would you be worried about the possibility of someone by mistake setting UnlimitedPropagation to nil?
There was a problem hiding this comment.
@bogdandrutu I have already made the change and uploaded. If everything looks fine then can you please approve it?
…mentation#1089) * Refactor gauge and registry to accomodate cummulative. - use common baseMetric type to manage gauge and cumulative. * fix copyright and renamed couple of func.
* Add support for cumulative. * fix review comments.
…n#1098) (census-instrumentation#1103) (cherry picked from commit a901c1e)
…nstrumentation#1102) * replace missing tag with empty values during metric export. * use map.
…n#1105) * Add prometheus support. * remove view related code and refactor metric specific code. * fix review comments. * remove dead code and fix comments. * fix error message.
|
@bogdandrutu , friendly reminder. |
|
Why closed? Do I still need to look at this? |
|
closed it by mistake. I'll reopen it. |
I have made all the changes you requested. You can approve if it looks good. |
|
@bogdandrutu friendly reminder. |
|
Please post a new PR to the |
|
opening a new PR on dev. |
No description provided.