Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

feat: support truncation of strings/bytes fields in protobuf logging #1192

Merged
merged 2 commits into from
Jan 16, 2020

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Jan 15, 2020

Extend internal::ConnectionImpl to hold the length to which protobuf
string/bytes fields should be truncated during gRPC request/response
logging, and pass it along to the logging wrappers. There it is used
in a special DebugString() implementation.

For now we just set it to a fixed value (256) until it is clear that
this is a direction we want to head, and until we decide how it should
be configured.


This change is Reviewable

Extend `internal::ConnectionImpl` to hold the length to which protobuf
string/bytes fields should be truncated during gRPC request/response
logging, and pass it along to the logging wrappers.  There it is used
in a special `DebugString()` implementation.

For now we just set it to a fixed value (256) until it is clear that
this is a direction we want to head, and until we decide how it should
be configured.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 15, 2020
@codecov
Copy link

codecov bot commented Jan 15, 2020

Codecov Report

Merging #1192 into master will increase coverage by 0.01%.
The diff coverage is 94.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1192      +/-   ##
==========================================
+ Coverage    95.7%   95.71%   +0.01%     
==========================================
  Files         174      180       +6     
  Lines       13601    13686      +85     
==========================================
+ Hits        13017    13100      +83     
- Misses        584      586       +2
Impacted Files Coverage Δ
google/cloud/spanner/internal/merge_chunk_test.cc 100% <ø> (ø) ⬆️
...ogle/cloud/spanner/internal/instance_admin_stub.cc 83.13% <0%> (-1.02%) ⬇️
...ogle/cloud/spanner/internal/database_admin_stub.cc 83.11% <0%> (-1.1%) ⬇️
...le/cloud/spanner/internal/instance_admin_logging.h 100% <100%> (ø) ⬆️
google/cloud/spanner/internal/log_wrapper_test.cc 100% <100%> (ø)
...ud/spanner/internal/database_admin_logging_test.cc 100% <100%> (ø) ⬆️
...le/cloud/spanner/internal/database_admin_logging.h 100% <100%> (ø) ⬆️
...cloud/spanner/internal/logging_result_set_reader.h 100% <100%> (ø) ⬆️
...spanner/internal/logging_result_set_reader_test.cc 100% <100%> (ø) ⬆️
google/cloud/spanner/connection_options.cc 91.89% <100%> (+0.71%) ⬆️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27048c7...99bba51. Read the comment docs.

Copy link
Member

@coryan coryan left a comment

Choose a reason for hiding this comment

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

Thank you for doing this. Feels like we should have at least one test to verify the the truncation actually happens?

Reviewed 21 of 21 files at r1.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @devbww)


google/cloud/spanner/connection_options.h, line 125 at r1 (raw file):

  /// Return the maximum length for string/bytes fields when tracing RPCs.
  std::int64_t max_text_proto_string_length() const {

nit: std::int64_t seems like an overkill for this, but probably more compatible with std::size_t.


google/cloud/spanner/connection_options.cc, line 53 at r1 (raw file):

    }
  }
  // TODO(XXX): Provide some way to override this from the environment.

Reminder: create an actual bug number to reference here.


google/cloud/spanner/internal/log_wrapper.h, line 23 at r1 (raw file):

#include "google/cloud/log.h"
#include "google/cloud/status_or.h"
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>

Do we use that?


google/cloud/spanner/internal/log_wrapper.h, line 35 at r1 (raw file):

template <typename Message>
std::string DebugString(Message const& m,

I do not think this needs to be a template, it can take a google::protobuf::Message const& m parameter?


google/cloud/spanner/internal/log_wrapper.h, line 40 at r1 (raw file):

  {
    google::protobuf::io::StringOutputStream os(&str);
    google::protobuf::TextFormat::Printer p;

FYI: There is also a Printer::PrintToString member function, would that not work?

https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format#TextFormat.Printer

There are also a number of other formatting options, including SetSingleLineMode() (which seems appropriate), UseShortRepeatedPrimitives, and others.

For this PR, I think setting SetSingleLineMode() is a good idea. For a future PR, maybe receive a struct with more options so we can extend the log formatting (seems like overkill, but had to be said).


google/cloud/spanner/internal/logging_spanner_stub.cc, line 17 at r1 (raw file):

#include "google/cloud/spanner/internal/logging_spanner_stub.h"
#include "google/cloud/spanner/internal/log_wrapper.h"
#include "google/cloud/internal/invoke_result.h"

Thanks!

- Support multiple tracing options, with useful defaults
- Override tracing options from `${GOOGLE_CLOUD_CPP_TRACING_OPTIONS}`
- Simplify `google::protobuf::TextFormat::Printer` usage
- Add tests
Copy link
Contributor Author

@devbww devbww left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 30 files reviewed, 4 unresolved discussions (waiting on @coryan)


google/cloud/spanner/connection_options.h, line 125 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

nit: std::int64_t seems like an overkill for this, but probably more compatible with std::size_t.

I chose std::int64_t to match the argument type to SetTruncateStringFieldLongerThan(). That avoid any conversions.


google/cloud/spanner/connection_options.cc, line 53 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

Reminder: create an actual bug number to reference here.

It is no longer a TODO.


google/cloud/spanner/internal/log_wrapper.h, line 23 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

Do we use that?

We did ... for google::protobuf::io::StringOutputStream. But your suggestion to use the PrintToString() wrapper obviates that. Thanks.


google/cloud/spanner/internal/log_wrapper.h, line 35 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

I do not think this needs to be a template, it can take a google::protobuf::Message const& m parameter?

Done.


google/cloud/spanner/internal/log_wrapper.h, line 40 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

FYI: There is also a Printer::PrintToString member function, would that not work?

https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format#TextFormat.Printer

There are also a number of other formatting options, including SetSingleLineMode() (which seems appropriate), UseShortRepeatedPrimitives, and others.

For this PR, I think setting SetSingleLineMode() is a good idea. For a future PR, maybe receive a struct with more options so we can extend the log formatting (seems like overkill, but had to be said).

Done.

@devbww devbww marked this pull request as ready for review January 16, 2020 07:32
Copy link
Member

@coryan coryan left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks again!

Reviewed 29 of 29 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


google/cloud/spanner/connection_options.h, line 125 at r1 (raw file):

Previously, devbww (Bradley White) wrote…

I chose std::int64_t to match the argument type to SetTruncateStringFieldLongerThan(). That avoid any conversions.

Ah, that makes sense.

@devbww devbww merged commit ffd5555 into googleapis:master Jan 16, 2020
@devbww devbww deleted the debugstring branch January 16, 2020 14:42
devjgm pushed a commit to devjgm/google-cloud-cpp that referenced this pull request May 7, 2020
…oogleapis/google-cloud-cpp-spanner#1192)

Add support for formatting options used during RPC request/response tracing.

The options, and their default values, are currently:
- single_line_mode=on
- use_short_repeated_primitives=on
- truncate_string_field_longer_than=128

`${GOOGLE_CLOUD_CPP_TRACING_OPTIONS}` can to set to a comma-separated list of "key=value" pairs to override these at runtime.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants