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

pmetrictest doesn't support ignore data point attribute values #27599

Closed
atoulme opened this issue Oct 10, 2023 · 5 comments
Closed

pmetrictest doesn't support ignore data point attribute values #27599

atoulme opened this issue Oct 10, 2023 · 5 comments
Labels
enhancement New feature or request pkg/pdatatest

Comments

@atoulme
Copy link
Contributor

atoulme commented Oct 10, 2023

Component(s)

pkg/pdatatest

Is your feature request related to a problem? Please describe.

pmetrictest supports ignoring resource attribute values and metric attribute values, but does not support ignoring data point attribute values.

right now the workaround is to modify the data set with:

func ignoreMetricDataPointAttributes(t *testing.T, metrics pmetric.Metrics, attributeNames ...string) {
	for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
		for j := 0; j < metrics.ResourceMetrics().At(i).ScopeMetrics().Len(); j++ {
			for k := 0; k < metrics.ResourceMetrics().At(i).ScopeMetrics().At(j).Metrics().Len(); k++ {
				metricToChange := metrics.ResourceMetrics().At(i).ScopeMetrics().At(j).Metrics().At(k)
				switch metricToChange.Type() {

				case pmetric.MetricTypeGauge:
					for l := 0; l < metricToChange.Gauge().DataPoints().Len(); l++ {
						dp := metricToChange.Gauge().DataPoints().At(l)
						dp.Attributes().Range(func(k string, v pcommon.Value) bool {
							for _, attributeName := range attributeNames {
								if k == attributeName {
									v.SetStr("*")
									break
								}
							}
							return true
						})
					}
				}
			}
		}
	}
}

Describe the solution you'd like

I would like to have the exact same option as offered by pmetrictest.IgnoreMetricAttributeValue

Describe alternatives you've considered

No response

Additional context

No response

@atoulme atoulme added the enhancement New feature or request label Oct 10, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@djaglowski
Copy link
Member

Is the function just poorly named? If I'm not mistaken, metrics do not directly have attributes, so this function is actually operating data point attributes.

@atoulme
Copy link
Contributor Author

atoulme commented Oct 12, 2023

Ah. It is. It also is surprising because it takes an attribute name and multiple metric names. Ideally I'd like both, but I can bear with it. I'll try it out and report back. Thank you for looking.

@djaglowski
Copy link
Member

We can certainly look at changing it. There's likely a more intuitive signature.

@atoulme
Copy link
Contributor Author

atoulme commented Oct 16, 2023

Going to close for now ; this is not a serious issue and while the API could be a bit clearer, I'm not sure it warrants a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/pdatatest
Projects
None yet
Development

No branches or pull requests

2 participants