Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Add support for tag metadata.#1032

Closed
rghetia wants to merge 11 commits intocensus-instrumentation:masterfrom
rghetia:tag_metadata
Closed

Add support for tag metadata.#1032
rghetia wants to merge 11 commits intocensus-instrumentation:masterfrom
rghetia:tag_metadata

Conversation

@rghetia
Copy link
Copy Markdown
Contributor

@rghetia rghetia commented Feb 21, 2019

No description provided.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Feb 21, 2019

This should be merged only after the spec pr is merged.

Copy link
Copy Markdown
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why pointer to metadata?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@rghetia rghetia requested a review from a team as a code owner March 20, 2019 23:04
@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 21, 2019

@bogdandrutu, @songy23 PTAL.

tag/metadata.go Outdated
var (
// TTLNoPropagation applies metadata with ttl value of valueTTLNoPropagation.
// It is predefined for convenience.
TTLNoPropagation = withTTL(valueTTLNoPropagation)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if we want to expose these constants here. See the comment at census-instrumentation/opencensus-java#1768 (comment).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious why this needs to be func?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
	}
}
     

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you could inadvertently modify UnlimitedPropagation and WithTTL would allow any value of TTL. I thought we don't want that at this point

Copy link
Copy Markdown
Contributor Author

@rghetia rghetia Mar 22, 2019

Choose a reason for hiding this comment

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

@rakyll would you be worried about the possibility of someone by mistake setting UnlimitedPropagation to nil?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's do it this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bogdandrutu I have already made the change and uploaded. If everything looks fine then can you please approve it?

rghetia added 6 commits April 3, 2019 10:05
…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.
…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.
@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Apr 15, 2019

@bogdandrutu , friendly reminder.

@rghetia rghetia closed this Apr 15, 2019
@rghetia rghetia deleted the tag_metadata branch April 15, 2019 20:43
@bogdandrutu
Copy link
Copy Markdown
Contributor

Why closed? Do I still need to look at this?

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Apr 15, 2019

closed it by mistake. I'll reopen it.

@rghetia rghetia restored the tag_metadata branch April 15, 2019 21:16
@rghetia rghetia reopened this Apr 15, 2019
@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Apr 15, 2019

Why closed? Do I still need to look at this?

I have made all the changes you requested. You can approve if it looks good.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Apr 18, 2019

@bogdandrutu friendly reminder.

@songy23
Copy link
Copy Markdown
Contributor

songy23 commented Apr 23, 2019

Please post a new PR to the dev branch. This one is to master.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Apr 23, 2019

opening a new PR on dev.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants