Skip to content

admin: add endpoint to access current runtime values#2353

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
rodaine:runtime-admin-endpoint
Jan 13, 2018
Merged

admin: add endpoint to access current runtime values#2353
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
rodaine:runtime-admin-endpoint

Conversation

@rodaine
Copy link
Copy Markdown
Member

@rodaine rodaine commented Jan 12, 2018

This patch adds a read-only admin endpoint to access runtime values. Values pairs are sorted by keys and available in either a human readable format or, with the query format=json, as JSON.

Risk Level: Small-Medium (new read-only endpoint on admin interface)
Testing: Unit + Integration
Docs Changes: envoyproxy/data-plane-api#414
Release Notes: Updated

Related: #514

Signed-off-by: Chris Roche <croche@lyft.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Super solid, thanks. A few comments. Please remove "fixes" from the description as we should keep the issue open until we also have modify support on the endpoint (via POST).

EXPECT_CALL(loader, snapshot()).WillRepeatedly(testing::ReturnPointee(&snapshot));
EXPECT_CALL(server_, runtime()).WillRepeatedly(testing::ReturnPointee(&loader));

EXPECT_EQ(Http::Code::BadRequest,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optimally, you would expect the help string that you expect here also.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done


std::unordered_map<std::string, const Runtime::Snapshot::Entry> entries{
{"string_key", {"foo", {}}}, {"int_key", {"1", {1}}}, {"other_key", {"bar", {}}}};
Runtime::MockSnapshot snapshot{};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: {} initializers for objects are redundant. I would remove them here and elsewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can take the boy out of Go...

}
)"};

EXPECT_NE(-1, response.search(json_format.data(), json_format.size(), 0));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: It would be a better test to actually parse the response as JSON using JSON loader and then check some values.

@dnoe
Copy link
Copy Markdown
Contributor

dnoe commented Jan 12, 2018

@htuch I'll take a pass over this later today

std::sort(pairs.begin(), pairs.end(),
[](const std::pair<std::string, const Runtime::Snapshot::Entry>& a,
const std::pair<std::string, const Runtime::Snapshot::Entry>& b) -> bool {
return a.first < b.first;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

std::pair implements operator<, so you could just say: std::sort(pairs.begin(), pairs.end()). The pair comparison function does what you'd expect: comparison by the first, then the second only if they are unequal. The lambda ignores the second if they are equal, of course, but std::sort isn't guaranteed to be a stable sort anyway.

Copy link
Copy Markdown
Member Author

@rodaine rodaine Jan 12, 2018

Choose a reason for hiding this comment

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

Without the lambda, the const Entry values result in errors:

error: invalid operands to binary expression ('const Envoy::Runtime::Snapshot::Entry' and 'const Envoy::Runtime::Snapshot::Entry')
    return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
                                                                 ~~~~~~~~~~ ^ ~~~~~~~~~~

I could implement operator< for Entry, but I figured that might be overkill given the usecase.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, OK. I think leave the lambda then. Thanks for looking into it!

@mattklein123 mattklein123 self-assigned this Jan 12, 2018
Signed-off-by: Chris Roche <croche@lyft.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, small remaining nit

EXPECT_EQ(Http::Code::OK, admin_.runCallback("/runtime", header_map, response));

const std::string std_format{"int_key: 1\nother_key: bar\nstring_key: foo\n"};
EXPECT_NE(-1, response.search(std_format.data(), std_format.size(), 0));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Collapse all of this into a single EXPECT_EQ without any local variable and use BufferToString. Same in bad format test.

Signed-off-by: Chris Roche <croche@lyft.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

sweet, thanks!

@mattklein123 mattklein123 merged commit 088573b into envoyproxy:master Jan 13, 2018
@rodaine rodaine deleted the runtime-admin-endpoint branch January 24, 2018 18:50
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
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.

3 participants