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

[WIP] Add Google Cloud Logging encoding to pubsub receiver #25175

Conversation

kamalmarhubi
Copy link
Contributor

Not for review yet!

refs #23184

Description:

Link to tracking Issue:

Testing:

Documentation:

Comment on lines +94 to +101
// TranslateLogEntry translates a JSON-encoded LogEntry message into a pair of
// pcommon.Resource and plog.LogRecord, trying to keep as close as possible to
// the semantic conventions.
//
// For maximum fidelity, the decoding is done according to the protobuf message
// schema; this ensures that a numeric value in the input is correctly
// translated to either an integer or a double in the output. It falls back to
// plain JSON decoding if payload type is not available in the proto registry.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the proto schema is responsible for a fair amount of the code here. It's arguably not worth the effort to avoid a few mistranslated numeric values. 🤷

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 just remembered that this isn't just about int vs float, it's also important for bytes, durations, and timestamps, all of which are both encoded as strings according to the protobuf json mapping. Actually checking that, it seems that all integers are to be encoded as strings, but can be decoded from either string or number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

additionally there should be an optional metric for unresolvable type uris so that people can know to add them if needed.

Comment on lines +17 to +19
import (
_ "google.golang.org/genproto/googleapis/cloud/audit"
)
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'd prefer to replace or augment this with functionality I'm hoping to propose in the builder, which allows adding go packages to be imported for side effects. this would let users add types they want accurate conversion for.

that is implemented here: kamalmarhubi/opentelemetry-collector@d846d4d

I initially wanted that for an approach I was considering for custom ottl functions: #16098 (comment)

but it would help here too, I think?

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added Stale and removed Stale labels Aug 27, 2023
@kamalmarhubi
Copy link
Contributor Author

not stale

@alexvanboxel
Copy link
Contributor

@kamalmarhubi I'm starting to work on this; I've checked out the branch locally (almost ready to test). Could you rebase against main, so it will be in a better state to merge.

Copy link
Contributor

@alexvanboxel alexvanboxel left a comment

Choose a reason for hiding this comment

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

This is a useful addition. I've added some comments. Let's rebase to main (and add documentation in the README) before converting this into a full PR.

switch k {
// Unpack as suggested in the logs data model appendix
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model-appendix.md#google-cloud-logging
case "timestamp":
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add LovEntry.receiveTimestamp, and map it to Proto(observed_time_unix_nano).

return res, lr, err
}
delete(src, k)
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

LogEntry.insertId can be mapped to Attribute(log.record.uid) (see https://opentelemetry.io/docs/specs/otel/logs/semantic_conventions/general/)

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 29, 2023
@alexvanboxel
Copy link
Contributor

Not stale... if the original author wants that I take over the branch and refactor I'm ok with that. @kamalmarhubi

@github-actions github-actions bot removed the Stale label Sep 30, 2023
@kamalmarhubi kamalmarhubi force-pushed the pubsub-google-cloud-logging branch from 73c7a80 to 51ae1da Compare October 8, 2023 17:54
Add a new `cloud_logging` encoding, which allows the receiver to
consume messages from a Pub/Sub topic that's used as the destination
of a Cloud Logging sink.

refs open-telemetry#23184
@kamalmarhubi
Copy link
Contributor Author

@alexvanboxel sorry for the slow response! I just rebased and pushed the branch, including your two recommendations (insertId, receiveTimestamp), and a very brief addition to the README. I haven't had time to add more realistic tests yet. If you're willing to take over the PR that works for me. Otherwise I'll do what I can!

@kamalmarhubi kamalmarhubi force-pushed the pubsub-google-cloud-logging branch from 51ae1da to 4e84241 Compare October 8, 2023 18:01
@kamalmarhubi
Copy link
Contributor Author

@alexvanboxel a couple of thoughts / questions:

  • would it make sense to get the MonitoredResource -> Resource translation happening here enshrined in the semantic conventions, possibly with changes? It would definitely slow down getting this merged, but would avoid a potential headache if the translation later has to change.
  • what if any metrics might make sense to add? The main one I'd be interested in is a count logs by jsonPayload["@type"], including whether the translation was driving by the proto descriptor or it's a lossy JSON fallback.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Oct 23, 2023
@alexvanboxel
Copy link
Contributor

Not stale, I would keep it MonitoredResource translation as is. If you don't mind, I'll keep the branch up-to-date and do some tweaks. I'll make sure to keep you credited as contributor.

@github-actions github-actions bot removed the Stale label Oct 24, 2023
@kamalmarhubi
Copy link
Contributor Author

@alexvanboxel

If you don't mind, I'll keep the branch up-to-date and do some tweaks. I'll make sure to keep you credited as contributor.

absolutely fine with me! let me know if there's anything else you'd like on my end. otherwise looking forward to this making it in :-)

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 16, 2023
@alexvanboxel
Copy link
Contributor

as agreed, I'll take over the branch (I will keep credits for the original commit to @kamalmarhubi). The branch can be found here: #29299

The branch is rebased against the latest release.

@github-actions github-actions bot removed the Stale label Nov 17, 2023
Copy link
Contributor

github-actions bot commented Dec 2, 2023

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Dec 2, 2023
@alexvanboxel
Copy link
Contributor

@kamalmarhubi can you close this draft, as the branch #29299 is being pushed through

@github-actions github-actions bot removed the Stale label Dec 17, 2023
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Dec 31, 2023
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Jan 15, 2024
@kamalmarhubi
Copy link
Contributor Author

Ah woops meant to close this since it was superseded by #29299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants