-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
admin: order stats in clusters json admin #4306
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,12 @@ message SimpleMetric { | |
GAUGE = 1; | ||
} | ||
|
||
// Type of metric represented. | ||
Type type = 1; | ||
// Name of the metric. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kept this in this order so that it comes in that order There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused here; are you saying the textual ordering in the proto spec dictates the wire format or JSON order? I would have thought the field numbers would dictate this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. Some thing wrong. Kept the same order as earlier |
||
string name = 3; | ||
|
||
// Current metric value. | ||
uint64 value = 2; | ||
|
||
// Type of the metric represented. | ||
Type type = 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,17 +284,18 @@ void AdminImpl::writeClustersAsJson(Buffer::Instance& response) { | |
envoy::admin::v2alpha::HostStatus& host_status = *cluster_status.add_host_statuses(); | ||
Network::Utility::addressToProtobufAddress(*host->address(), | ||
*host_status.mutable_address()); | ||
|
||
for (const Stats::CounterSharedPtr& counter : host->counters()) { | ||
auto& metric = (*host_status.mutable_stats())[counter->name()]; | ||
metric.set_type(envoy::admin::v2alpha::SimpleMetric::COUNTER); | ||
auto& metric = *host_status.add_stats(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, the order that you iterate through these stats is dictated by their order in this unordered_map. In what situations would you like to have the ordering stay the same? I think your test could break in the future if the unordered_map internals (like its hash function) change. There are a few solutions here:
|
||
metric.set_name(counter->name()); | ||
metric.set_value(counter->value()); | ||
metric.set_type(envoy::admin::v2alpha::SimpleMetric::COUNTER); | ||
} | ||
|
||
for (const Stats::GaugeSharedPtr& gauge : host->gauges()) { | ||
auto& metric = (*host_status.mutable_stats())[gauge->name()]; | ||
metric.set_type(envoy::admin::v2alpha::SimpleMetric::GAUGE); | ||
auto& metric = *host_status.add_stats(); | ||
metric.set_name(gauge->name()); | ||
metric.set_value(gauge->value()); | ||
metric.set_type(envoy::admin::v2alpha::SimpleMetric::GAUGE); | ||
} | ||
|
||
envoy::admin::v2alpha::HostHealthStatus& health_status = | ||
|
@@ -314,7 +315,7 @@ void AdminImpl::writeClustersAsJson(Buffer::Instance& response) { | |
} | ||
} | ||
} | ||
response.add(MessageUtil::getJsonStringFromMessage(clusters, true)); // pretty-print | ||
response.add(MessageUtil::getJsonStringFromMessage(clusters, true, true)); // pretty-print | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a quick comment on this behavior change? I think if we want to do this, we should probably change it in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I think then, I lean to revert this for consistency. |
||
} | ||
|
||
void AdminImpl::writeClustersAsText(Buffer::Instance& response) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
List
(to match the surrounding comments)