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

Apply new experimental metrics builder to hostmetrics/cpu scraper #6418

Merged
merged 1 commit into from
Dec 2, 2021

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Nov 23, 2021

Introduce new experimental metrics builder interface for metrics scrapers and apply it to hostmetrics/cpu scraper.

Link to tracking Issue: open-telemetry/opentelemetry-collector#10904

@dmitryax dmitryax requested review from a team and kbrockhoff November 23, 2021 21:05
@dmitryax dmitryax changed the title Apply new experimental metrics builder for hostmetrics/cpu scraper Apply new experimental metrics builder to hostmetrics/cpu scraper Nov 23, 2021
@dmitryax dmitryax force-pushed the add-exp-metadata-gen branch 2 times, most recently from a3444d5 to 01b3521 Compare November 23, 2021 21:53
withStartTime := metadata.WithStartTime(pdata.Timestamp(bootTime * 1e9))
withStatesCapacity := metadata.WithAttributeStateCapacity(cpuStatesLen)
withCoresCapacity := metadata.WithAttributeCpuCapacity(runtime.NumCPU())
s.mb = metadata.NewMetricsBuilder(s.config.Metrics, withStartTime, withStatesCapacity, withCoresCapacity)
Copy link
Member

@djaglowski djaglowski Nov 30, 2021

Choose a reason for hiding this comment

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

Some scrapers will have many more "Capacity" parameters. Should we render these into separate functions, perhaps like this?

s.mb = metadata.NewMetricsBuilder(s.config.Metrics, withStartTime).
                WithStatesCapacity(withStatesCapacity).
                WithCoresCapacity(withCoresCapacity)

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case I would change it for all including withStartTime. I like it, but seems like it's not very common pattern in the collector's codebase. @bogdandrutu what's your thought on this?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is the most "go" way to have this:

s.mb = metadata.NewMetricsBuilder(
	s.config.Metrics,
	metadata.WithStartTime(pdata.Timestamp(bootTime * 1e9)),
	metadata.WithAttributeStateCapacity(cpuStatesLen),
	metadata.WithAttributeCpuCapacity(runtime.NumCPU()))

@dmitryax dmitryax force-pushed the add-exp-metadata-gen branch 5 times, most recently from 336f0f5 to 505d64a Compare December 1, 2021 02:29
Introduce new experimental metrics builder interface for metrics scrapers and apply it to hostmetrics/cpu scraper.
func (mb *MetricsBuilder) Emit(metrics pdata.MetricSlice) {
{{- range $name, $metric := .Metrics }}
if mb.config.{{- $name.Render }}.Enabled {
mb.metrics.{{- $name.Render }}.CopyTo(metrics.AppendEmpty())
Copy link
Member

Choose a reason for hiding this comment

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

MoveTo?

@bogdandrutu bogdandrutu merged commit f59ddc2 into open-telemetry:main Dec 2, 2021
@dmitryax dmitryax deleted the add-exp-metadata-gen branch December 2, 2021 23:29
jamesmoessis pushed a commit to atlassian-forks/opentelemetry-collector-contrib that referenced this pull request Dec 8, 2021
…pen-telemetry#6418)

Introduce new experimental metrics builder interface for metrics scrapers and apply it to hostmetrics/cpu scraper.
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