Skip to content

Issue 596: Add profiler path to configuration#603

Merged
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
hennna:issue-596
Mar 22, 2017
Merged

Issue 596: Add profiler path to configuration#603
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
hennna:issue-596

Conversation

@hennna
Copy link
Contributor

@hennna hennna commented Mar 21, 2017

Step 1

  • Added profiler_path_ member variable to AdminImpl class. Allows profiler path to be configurable rather than hard coded.
  • Return Http::Code::BadRequest when call to Cpu::startProfiler(...) fails.

Step 2

  • Update admin profiler_path JSON configuration

Issue link: #596

@htuch for comments.

@hennna hennna closed this Mar 22, 2017
@hennna hennna deleted the issue-596 branch March 22, 2017 00:15
@hennna hennna restored the issue-596 branch March 22, 2017 00:22
@hennna hennna reopened this Mar 22, 2017
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Overall, looks great. Mostly minor comments.

*/
virtual const std::string& accessLogPath() PURE;

/**
Copy link
Member

Choose a reason for hiding this comment

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

Actually, it might be more semantically correct to call this profilePath (and similar renames elsewhere). It's where the profile is emitted, not the profiler itself. The comment might then be "@return const std::string& profiler output path."

"type" : "object",
"properties" : {
"access_log_path" : {"type" : "string"},
"profiler_path" : {"type" : "string"},
Copy link
Member

Choose a reason for hiding this comment

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

Ditto etc.

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 change config_schemas.cc, it's usually also necessary to update the user configuration docs. In this case, the file to update is https://github.com/lyft/envoy/blob/master/docs/configuration/overview/admin.rst.

Copy link
Member

Choose a reason for hiding this comment

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

You can also defer the config_schemas.cc change to your next PR, since it's not used yet here.

* Start the profiler and write to the specified path.
*/
static void startProfiler(const std::string& output_path);
static bool startProfiler(const std::string& output_path);
Copy link
Member

Choose a reason for hiding this comment

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

Add some return value documentation.

MAKE_HANDLER(handlerServerInfo)},
{"/stats", "print server stats", MAKE_HANDLER(handlerStats)}} {

profiler_path_ = profiler_path;
Copy link
Member

Choose a reason for hiding this comment

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

It might be nicer to initialize this in the above constructor member initialization list, i.e.

: server_(server), ..., profiler_path_(profiler_path)

EXPECT_TRUE(response->complete());
EXPECT_STREQ("400", response->headers().Status()->value().c_str());

// TO DO: Change to expect 200 when profiler path is a configurable parameter
Copy link
Member

Choose a reason for hiding this comment

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

The convention used in Envoy is TODO(hennna): foo bar.

Profiler::Cpu::startProfiler("/var/log/envoy/envoy.prof");
if (!Profiler::Cpu::startProfiler(profiler_path_)) {
response.add("?enable=<y|n>\n");
return Http::Code::BadRequest;
Copy link
Member

Choose a reason for hiding this comment

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

This returns a 400. I think it's not actually a bad client formed request, it's an internal server error, so you want to return a 500.

if (enable && !Profiler::Cpu::profilerEnabled()) {
Profiler::Cpu::startProfiler("/var/log/envoy/envoy.prof");
if (!Profiler::Cpu::startProfiler(profiler_path_)) {
response.add("?enable=<y|n>\n");
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 a more meaningful response would indicate there was a failure to start the profiler.


NiceMock<MockInstance> server_;
AdminImpl admin_;
AdminImpl admin_bad_profiler_path_;
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 think this needs to be a member of AdminFilterTest, it can be just allocated and instantiated locally in AdminBadProfiler.

// TODO(mattklein123): Switch to mocks and do not bind to a real port.
AdminFilterTest()
: admin_("/dev/null", Network::Utility::resolveUrl("tcp://127.0.0.1:9002"), server_),
: admin_("/dev/null", "/tmp/envoy.prof", Network::Utility::resolveUrl("tcp://127.0.0.1:9002"),
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a fault in this PR (it's a widespread issue in Envoy today), but using /tmp is kind of dangerous, since you may conflict with other users or test runs in a shared environment. You can keep the code as is, since we don't have a better solution yet, but add a TODO(htuch): Use proper temporary path allocation method. here?

Copy link
Member

Choose a reason for hiding this comment

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

I've filed #605 to track this work.

@mattklein123
Copy link
Member

@hennna please sign CLA if you didn't already.

@hennna
Copy link
Contributor Author

hennna commented Mar 22, 2017

@mattklein123 just signed CLA


/**
* Start the profiler and write to the specified path.
* @return bool whether the call to start profiler succeeded.
Copy link
Member

Choose a reason for hiding this comment

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

nit: "start the profiler"


Server::Instance& server_;
std::list<Http::AccessLog::InstanceSharedPtr> access_logs_;
std::string profile_path_;
Copy link
Member

Choose a reason for hiding this comment

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

const

#ifdef TCMALLOC

TEST_F(IntegrationTest, AdminCpuProfilerStart) {
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
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 think you meant to move this request ("/") inside here. Should go back in other section.


TEST_F(AdminFilterTest, AdminBadProfiler) {
Buffer::OwnedImpl data;
AdminImpl admin_bad_profile_path("/dev/null", "/var/log/envoy/envoy.prof",
Copy link
Member

Choose a reason for hiding this comment

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

This is not going to fail in all envs. I would use a totally bogus path here.

{"/server_info", "print server version/status information",
MAKE_HANDLER(handlerServerInfo)},
{"/stats", "print server stats", MAKE_HANDLER(handlerStats)}} {

Copy link
Member

Choose a reason for hiding this comment

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

Nit: unrelated line deletion?

EXPECT_STREQ("200", response->headers().Status()->value().c_str());

response = IntegrationUtil::makeSingleRequest(ADMIN_PORT, "GET", "/hot_restart_version", "",
response = IntegrationUtil::makeSingleRequest(ADMIN_PORT, "GET", "/certs", "",
Copy link
Member

Choose a reason for hiding this comment

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

What's going on with all these handler path changes? They don't seem related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the two enable=y and enable=n into it's own integration test called AdminCpuProfilerStart. I think this has to do with line order changes.


TEST_F(AdminFilterTest, AdminBadProfiler) {
Buffer::OwnedImpl data;
AdminImpl admin_bad_profile_path("/dev/null", "/var/log/envoy/envoy.prof",
Copy link
Member

Choose a reason for hiding this comment

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

/var/log/envoy/envoy.prof might be a valid path in some environments. Maybe use /some/unlikely/bad/path.prof for now, we should deal with this better when cleaning up the temp file story. Another approach would be to mock file handling, but I think this is a bit of clutter and overhead to put this dependency injection into AdminImpl.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM.

@mattklein123 mattklein123 merged commit 16f197c into envoyproxy:master Mar 22, 2017
@hennna hennna deleted the issue-596 branch March 23, 2017 21:52
rshriram pushed a commit to rshriram/envoy that referenced this pull request Oct 30, 2018
Automatic merge from submit-queue

[DO NOT MERGE] Auto PR to update dependencies of proxy

This PR will be merged automatically once checks are successful.
```release-note
none
```
PiotrSikora pushed a commit to PiotrSikora/envoy that referenced this pull request Aug 7, 2020
Signed-off-by: John Plevyak <jplevyak@gmail.com>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: currently apps would fail in IPv6 only networks. This configuration change makes it so that the default setting is used, which is AUTO.
Risk Level: low
Testing: will test on device

Thanks to @theatrus for reporting!

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: currently apps would fail in IPv6 only networks. This configuration change makes it so that the default setting is used, which is AUTO.
Risk Level: low
Testing: will test on device

Thanks to @theatrus for reporting!

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.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