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 TCP Access Logging #2852

Merged
merged 7 commits into from Jun 8, 2020
Merged

Conversation

gargnupur
Copy link
Contributor

@gargnupur gargnupur commented May 14, 2020

What this PR does / why we need it:
This is built on top of #2843

Ref: istio/istio#23134

@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 14, 2020
@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label May 14, 2020
@istio-testing istio-testing added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-rebase Indicates a PR needs to be rebased before being merged labels May 14, 2020
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label May 25, 2020
@gargnupur gargnupur changed the title [WIP]: Add TCP Access Logging Add TCP Access Logging May 25, 2020
@gargnupur gargnupur removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 25, 2020
@gargnupur gargnupur marked this pull request as ready for review May 25, 2020 23:03
@gargnupur gargnupur requested a review from a team May 25, 2020 23:03
@gargnupur gargnupur requested a review from a team as a code owner May 25, 2020 23:03
Signed-off-by: gargnupur <gargnupur@google.com>

fix

Signed-off-by: gargnupur <gargnupur@google.com>

changes

Signed-off-by: gargnupur <gargnupur@google.com>

refactor

Signed-off-by: gargnupur <gargnupur@google.com>

fix test

Add TCP Metrics in Stackdriver

Signed-off-by: gargnupur <gargnupur@google.com>

fix

Signed-off-by: gargnupur <gargnupur@google.com>

Add TCP access logging

changes

Signed-off-by: gargnupur <gargnupur@google.com>

Remove local path from Makefile

changes

Signed-off-by: gargnupur <gargnupur@google.com>

Add functions for queue

fix build

fix test

remove debug time

Signed-off-by: gargnupur <gargnupur@google.com>

remove debug time

Signed-off-by: gargnupur <gargnupur@google.com>

Add protocol in http accesslog
Signed-off-by: gargnupur <gargnupur@google.com>
@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 4, 2020
Signed-off-by: gargnupur <gargnupur@google.com>
@gargnupur
Copy link
Contributor Author

@bianpengyuan , @mandarjog , @douglas-reid : This is ready for review..

message PluginConfig {
// Optional. Controls whether to export server access log.
bool disable_server_access_logging = 1;

// Optional. Controls whether to export TCP server access log.
bool disable_tcp_server_access_logging = 9;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we just use disable_server_access_logging to control both tcp and http logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.. removing

const ::Wasm::Common::RequestInfo& request_info,
google::logging::v2::LogEntry* log_entry) {
auto label_map = log_entry->mutable_labels();
(*label_map)["tcp_remote_ip"] = request_info.source_address;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need tcp prefix? What did we use in mixer v1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed them to match mixer v1

@@ -403,6 +404,12 @@ bool StackdriverRootContext::recordTCP(uint32_t id) {
// Record TCP Metrics.
::Extensions::Stackdriver::Metric::recordTCP(outbound, local_node, peer_node,
request_info);
// Add LogEntry to Logger. Log Entries are batched and sent on timer
// to Stackdriver Logging Service.
if (enableTCPServerAccessLog() && shouldLogThisRequest()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does shouldLogThisRequest apply here? It only bases on http or grpc status right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed for now.. but I was thinking more in terms of sampling successful connections too but will change accesslog sampling filter to select failed request based on presence of response flag.. will do in a separate PR

// to Stackdriver Logging Service.
if (enableTCPServerAccessLog() && shouldLogThisRequest()) {
::Wasm::Common::populateExtendedRequestInfo(&request_info);
logger_->addLogEntry(request_info, peer_node, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger_->addLogEntry(request_info, peer_node, true);
logger_->addLogEntry(request_info, peer_node, /* is_tcp = */ true);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -351,7 +352,7 @@ void StackdriverRootContext::record() {
!config_.disable_http_size_metrics());
if (enableServerAccessLog() && shouldLogThisRequest()) {
::Wasm::Common::populateExtendedHTTPRequestInfo(&request_info);
logger_->addLogEntry(request_info, peer_node);
logger_->addLogEntry(request_info, peer_node, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger_->addLogEntry(request_info, peer_node, false);
logger_->addLogEntry(request_info, peer_node, /* is_tcp = */ false);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -80,7 +80,11 @@ class StackdriverRootContext : public RootContext {
void deleteFromTCPRequestQueue(uint32_t id);
void incrementReceivedBytes(uint32_t id, size_t size);
void incrementSentBytes(uint32_t id, size_t size);
void incrementTotalReceivedBytes(uint32_t id, size_t size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not reuse the existing functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the metrics are different... this is incrementing tcp_total_received_bytes...

Copy link
Contributor

Choose a reason for hiding this comment

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

You can increment total_x_bytes inside the existing function.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not fixed yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup. thanks.. fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a new commit, did you push?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

weird.. change was there in the branch bot not in PR.. I pushed again with a comment.. PTAL

@@ -155,6 +162,8 @@ class StackdriverContext : public Context {

is_tcp_ = true;
getRootContext()->addToTCPRequestQueue(context_id_);
getRootContext()->setConnectionState(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you will need to trigger log record in connection open, otherwise it will not be recorded. Also I think it is necessary to record log entry in open and close event, so that they could have correct time stamp.

Copy link
Contributor

Choose a reason for hiding this comment

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

And test make sure that all three types of connection states are covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.. I was going to ping you offline about this :) I had exact same question in my other PR.. #2843 (comment) but reading it now, I think you were referring to Metrics and I was referring to calling Record method in general that does everything.

One of the things for TCP would be that metadata exchange doesn't happen until data comes so, connection open log won't have peer data. But it would be good to still get connection open logged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add this change in a separate PR because of metadata exchange stuff..

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I think time stamp is the only thing special with connection open. All other labels should have no difference from other state. You can keep an connection open time stamp somewhere and use that as a signal to record connection open event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to fix this in separated PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will do in a separate PR.. started a conversation about this with you, Mandar and Doug..

Signed-off-by: gargnupur <gargnupur@google.com>
@@ -203,7 +204,7 @@ bool StackdriverRootContext::configure(size_t configuration_size) {
}
}

if (!logger_ && enableServerAccessLog()) {
if (!logger_ && (enableServerAccessLog())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!logger_ && (enableServerAccessLog())) {
if (!logger_ && enableServerAccessLog()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks..Fixed

@@ -313,7 +314,7 @@ bool StackdriverRootContext::onDone() {
// called, but onConfigure is not triggered. onConfigure is only triggered in
// thread local VM, which makes it possible that logger_ is empty ptr even
// when logging is enabled.
if (logger_ && enableServerAccessLog() &&
if (logger_ && (enableServerAccessLog()) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (logger_ && (enableServerAccessLog()) &&
if (logger_ && enableServerAccessLog() &&

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks..Fixed

@@ -155,6 +162,8 @@ class StackdriverContext : public Context {

is_tcp_ = true;
getRootContext()->addToTCPRequestQueue(context_id_);
getRootContext()->setConnectionState(
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to fix this in separated PR?

@@ -80,7 +80,11 @@ class StackdriverRootContext : public RootContext {
void deleteFromTCPRequestQueue(uint32_t id);
void incrementReceivedBytes(uint32_t id, size_t size);
void incrementSentBytes(uint32_t id, size_t size);
void incrementTotalReceivedBytes(uint32_t id, size_t size);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not fixed yet.

Signed-off-by: gargnupur <gargnupur@google.com>
@istio-testing istio-testing merged commit ea0ce55 into istio:master Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
4 participants