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

Add MetricRecorder implementation #11128

Merged
merged 7 commits into from Apr 26, 2024
Merged

Conversation

DNVindhya
Copy link
Contributor

This PR adds an internal implementation for MetricRecorder interface. And adds unit tests for MetricInstrumentRegistry.

// Measures may need updating in two cases:
// 1. When the sink is initially created with an empty list of measures.
// 2. When new metric instruments are registered, requiring the sink to accommodate them.
sink.updateMeasures(registry.getMetricInstruments());
Copy link
Member

Choose a reason for hiding this comment

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

When you implement the sink, you'll need to check whether there are actually any new elements. With this threading, later calls to updateMeasures() can show fewer entries. That can be okay. The sink just needs to ignore the cases when there's no new entries.

api/src/main/java/io/grpc/MetricInstrumentRegistry.java Outdated Show resolved Hide resolved
api/src/main/java/io/grpc/MetricInstrumentRegistry.java Outdated Show resolved Hide resolved
@DNVindhya DNVindhya changed the title Added MetricRecorder implementation Add MetricRecorder implementation Apr 25, 2024
* @param requiredLabelValues A list of required label values for the metric.
* @param optionalLabelValues A list of additional, optional label values for the metric.
*/
default void recordDoubleCounter(DoubleCounterMetricInstrument metricInstrument, double value,
default void addDoubleCounter(DoubleCounterMetricInstrument metricInstrument, double value,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@temawi updated counter APIs. Can you PTAL?

this(new ArrayList<>(DEFAULT_INSTRUMENT_LIST_CAPACITY), new HashSet<>());
}
private volatile MetricInstrument[] metricInstruments;
private volatile int instrumentListCapacity = INITIAL_INSTRUMENT_CAPACITY;
Copy link
Member

Choose a reason for hiding this comment

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

Use metricInstruments.length instead

api/src/main/java/io/grpc/MetricInstrumentRegistry.java Outdated Show resolved Hide resolved
private final List<MetricInstrument> metricInstruments;
private final Set<String> registeredMetricNames;
private final Object lock = new Object();
private final Set<String> registeredMetricNames = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

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

@GuardedBy("lock")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@DNVindhya DNVindhya merged commit 795ee0f into grpc:master Apr 26, 2024
13 checks passed
@DNVindhya DNVindhya deleted the arch-metric-recorder branch April 26, 2024 20:47
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.

None yet

3 participants