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

Metrics: Synchronous gauges respect attributes #101018

Closed
wants to merge 2 commits into from

Conversation

stu-elastic
Copy link
Contributor

Synchronous gauges would only accept the most recent value, regardless of matching attributes. As attributes should be treated as dimensions, we keep the most recent value with matching attributes.

Synchronous gauges would only accept the most recent value, regardless of
matching attributes.  As attributes should be treated as dimensions, we keep
the most recent value with matching attributes.
@stu-elastic stu-elastic added >bug :Core/Infra/Core Core issues without another label labels Oct 17, 2023
@elasticsearchmachine elasticsearchmachine added v8.12.0 Team:Core/Infra Meta label for core/infra team labels Oct 17, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Collaborator

Hi @stu-elastic, I've created a changelog YAML for you.

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

I left some comments
at some point apm-java-agent should provide us with synchronous gague implementation, so perhaps we don't need to worry about this too much open-telemetry/opentelemetry-java#5506
@JonasKunz do you know when we could use it? once it stop being experimental?

}

// testing that a value reported is then used in a callback
@SuppressWarnings("unchecked")
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we can remove this now

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to remove it, since we no longer have an unchecked cast here

LongGaugeAdapter gauge1 = new LongGaugeAdapter(meter, "name1", "desc", "unit");
LongGaugeAdapter gauge2 = new LongGaugeAdapter(meter, "name2", "desc", "unit");
Map<String, Object> map = Map.of("k", 1L);
gauge1.record(1L, map);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this test called same values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh it should be same attributes.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we then rename the test?

* Side Public License, v 1.
*/

package org.elasticsearch.telemetry.apm.internal.metrics;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we not have test framework classes in separate PR?
on the other side we have some example usage of it in this PR, so maybe it is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The full framework is in #100977 but I'm having some dependency issues. I didn't want to keep blocking progress on gauges on that.

}
}

private final Map<INSTRUMENT, RegisteredMetric> doubles;
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if Instrument would not read better
I was looking for a generic INSTRUMENT here because of capital casing

Copy link
Contributor

Choose a reason for hiding this comment

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

just a ping, that it would be great to rename this before merging

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

I left few comments, I think we might be missing some changes from the previous discussions.
were we not planning to implement the testing version of org.elasticsearch.telemetry.metric.Meter without otel?

}

// testing that a value reported is then used in a callback
@SuppressWarnings("unchecked")
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to remove it, since we no longer have an unchecked cast here

LongGaugeAdapter gauge1 = new LongGaugeAdapter(meter, "name1", "desc", "unit");
LongGaugeAdapter gauge2 = new LongGaugeAdapter(meter, "name2", "desc", "unit");
Map<String, Object> map = Map.of("k", 1L);
gauge1.record(1L, map);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we then rename the test?

}
}

private final Map<INSTRUMENT, RegisteredMetric> doubles;
Copy link
Contributor

Choose a reason for hiding this comment

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

just a ping, that it would be great to rename this before merging

assertThat(testLongMeasurement.attributes, Matchers.equalTo(Attributes.builder().put("k", 1).build()));
meter.collectMetrics();
metrics = meter.getRecorder().get(gauge);
assertThat(metrics, hasSize(2));
Copy link
Contributor

Choose a reason for hiding this comment

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

if you check containsInAnyOrder you don't need to check for a size. It would fail if an actual collection has less,more elements then expected matchers

return recorder;
}

private MeterRecorder recorder = new MeterRecorder();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we fix the order? fields first, methods later.
might be worth being concistent with field accessors


package org.elasticsearch.telemetry.apm.internal.metrics;

import io.opentelemetry.api.common.Attributes;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really have to implement an otel api in test framework?
can we not limit ourselfs to just implementing the recording version of the org.elasticsearch.telemetry.metric.Meter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants