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] gRPC Non-Per-Call Metrics framework implementation #35871

Closed
wants to merge 18 commits into from

Conversation

yijiem
Copy link
Member

@yijiem yijiem commented Feb 9, 2024

No description provided.

@yijiem yijiem added the release notes: no Indicates if PR should not be in release notes label Feb 9, 2024
@yijiem yijiem requested a review from yashykt February 9, 2024 00:44
// Creates instrument in the GlobalInstrumentsRegistry.
static GlobalUInt64CounterHandle RegisterUInt64Counter(
absl::string_view name, absl::string_view description,
absl::string_view unit, std::vector<absl::string_view> label_keys,
Copy link
Member

Choose a reason for hiding this comment

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

Note that we want the MakeValueSet optimization here, but I see the TODO down below, so I'm fine with this as a first iteration

src/core/lib/channel/metrics.h Show resolved Hide resolved
}

template <class T>
std::string MakeKey(T t) {
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 weird. I would much prefer you just create a FakeCounter and a FakeHistogram. That's going to make much more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this. The FakeStatsPlugin creates an instrument for each instruments in the GlobalInstrumentsRegistry. It now uses the index to find the instrument that it created (as it should be used IIUC).

absl::string_view unit, std::vector<absl::string_view> label_keys,
std::vector<absl::string_view> optional_label_keys);

static const GlobalCounterDescriptor& GetCounterDescriptor(
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point of the GetCounterDescriptor() or GetHistogramDescriptor() methods. We could just use the counters() or histograms() methods and use the handle as an index directly?

Copy link
Member

Choose a reason for hiding this comment

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

If you are thinking of this as just a convenience method, I'm fine with it

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed. I combined counters() and histograms() into a single instruments() method, PTAL.

namespace grpc_core {

// Static only.
class GlobalInstrumentsRegistry {
Copy link
Member

Choose a reason for hiding this comment

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

"Static initialization"

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

std::vector<absl::string_view> label_keys;
std::vector<absl::string_view> optional_label_keys;
};
struct GlobalHandle {
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 we should make it clear that we are using the handle as an index in docs, and that that is an API. (unless, we want to hide the fact that handle is just an index)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some comment about the index. I think we can expose it so that StatsPlugins can use it to uniquely identify an instrument later with the handle. PTAL.

Copy link
Member

Choose a reason for hiding this comment

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

GlobalInstrumentHandle? I think grpc_core::GlobalHandle sounds very generic

Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks like a great start!

Please let me know if you have any questions. Thanks!

src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
Copy link
Member Author

@yijiem yijiem left a comment

Choose a reason for hiding this comment

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

Thanks Mark!

src/core/lib/channel/metrics.cc Outdated Show resolved Hide resolved
namespace grpc_core {

// Static only.
class GlobalInstrumentsRegistry {
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks great! Remaining comments are minor.

Please let me know if you have any questions. Thanks!

src/core/lib/channel/metrics.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
test/core/channel/metrics_test.cc Outdated Show resolved Hide resolved
src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
@markdroth
Copy link
Member

This looks great! The only remaining issue is the one about not wrapping the ChannelScope object.

markdroth
markdroth previously approved these changes Feb 22, 2024
Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

Looks great, modulo one minor comment. Feel free to merge after addressing.

Nice work!

src/core/lib/channel/metrics.h Outdated Show resolved Hide resolved
@markdroth markdroth changed the title [Metrics] gRPC Metrics framework implementation [Metrics] gRPC Non-Per-Call Metrics framework implementation Feb 22, 2024
@markdroth markdroth dismissed their stale review February 22, 2024 18:23

I realized we need one more thing.

Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks fabulous! Feel free to merge after addressing the remaining comment.

channel_filter)
: channel_filter_(std::move(channel_filter)) {
GlobalInstrumentsRegistry::ForEach(
[this](const GlobalInstrumentsRegistry::GlobalInstrumentDescriptor&
descriptor) {
if (!descriptor.enable_by_default) {
Copy link
Member

Choose a reason for hiding this comment

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

Please also add a test that covers adding a metric that is not enabled by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

Looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants