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

Extract CWlogs client from EMF exporter and use in Awscloudwatchlogsexporter #6969

Closed

Conversation

aateeqi
Copy link
Contributor

@aateeqi aateeqi commented Dec 28, 2021

Description:
Currently the awscloudwatchlogs exporter is missing some desired functionality based on the issues linked below. Since the awsemfexporter already supports some of this functionality, this PR copies and packages this emf logic into a cloudwatch internal component to push to cloudwatch logs.

The follow-up of this PR would be to hook up the awsemfexporter to also call the cloudwatch package to push metrics to cloudwatch.

  1. Enable awscloudwatchlogsexporter
  2. Package awsemfexporter pusher and cw_client components into cloudwatch internal component that supports:
    - automatically creating log group and log stream on push
    - batch logs to 256 kb

Link to tracking Issue:
#6991

Testing:
built and ran the otel agent with the following that reads from a local file (/var/log/depnotify.log) and verified that the logs were pushed to cloudwatch with no errors

`receivers:
filelog:
start_at: beginning
include: [ /var/log/depnotify.log ]
otlp:
protocols:
http:
grpc:
endpoint: 0.0.0.0:4317

exporters:
logging:
awsxray:
region: us-west-2
awscloudwatchlogs:
log_group_name: test-sample-group
log_stream_name: test-sample-stream
region: us-west-2

service:
telemetry:
logs:
pipelines:
logs:
receivers:
- otlp
- filelog
exporters:
- awscloudwatchlogs`

Documentation:

TODO

…nent to push logs, create log group/stream in cloudwatch
@aateeqi aateeqi requested a review from anuraaga as a code owner December 28, 2021 04:34
@aateeqi aateeqi requested a review from a team December 28, 2021 04:34
@aateeqi aateeqi marked this pull request as draft December 28, 2021 16:28
Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

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

There is a lot that needs to be addressed within this PR and I am not certain the current approach aligns with the issues linked.

exporter/awscloudwatchlogsexporter/exporter.go Outdated Show resolved Hide resolved
exporter/awscloudwatchlogsexporter/exporter.go Outdated Show resolved Hide resolved
seqTokenMu sync.Mutex
seqToken string
groupStreamToPusherMap map[string]map[string]cloudwatch.Pusher
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 overly verbose name, is there any way to make this concise?

exporter/awscloudwatchlogsexporter/exporter.go Outdated Show resolved Hide resolved
exporter/awscloudwatchlogsexporter/exporter.go Outdated Show resolved Hide resolved
if batch.minTimestampMs == 0 || batch.maxTimestampMs == 0 {
return true
}
if *targetTimestampMs-batch.minTimestampMs > 24*3600*1e3 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid using magic numbers

// log part and retry logic are already done inside the CreateStream
// when the error is not nil, the stream token is "", which is handled in the below logic.
p.streamToken, err = p.svcStructuredLog.CreateStream(p.logGroupName, p.logStreamName)
// TODO Known issue: createStream will fail if the corresponding logGroup and logStream has been created.
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no todo, only dos in my reviews.

// TODO Known issue: createStream will fail if the corresponding logGroup and logStream has been created.
// The retry mechanism helps get the first stream token, yet the first batch will be sent twice in this situation.
if err != nil {
p.logger.Warn("Failed to create stream token", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably fail the method right?


var tmpToken *string
var err error
p.logger.Info("PUTTING LOG EVENTS")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this to debug, and use normal casing.


tmpToken, err = p.svcStructuredLog.PutLogEvents(putLogEventsInput, p.retryCnt)

p.logger.Info("tmp token is %v", zap.String("tmpToken", *tmpToken))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use a formatted string for logging.

@MovieStoreGuy
Copy link
Contributor

I am not sure this approach is what @rakyll had visioned for #3697

@MovieStoreGuy
Copy link
Contributor

This is a very large PR @aateeqi ,

Please consider breaking this down into smaller PRs

@Aneurysm9
Copy link
Member

I am not sure this approach is what @rakyll had visioned for #3697

I discussed this with @aateeqi last week and I think this is the first of several steps that will be necessary to unify the EMF and CW logs exporters:

  1. Extract the CW logs client from the EMF exporter
  2. Use that client in the CW logs exporter
  3. Use the extracted version of the client in the EMF exporter
  4. Copy the EMF metrics handling to the CW exporter
  5. Mark the EMF exporter as deprecated
  6. There is no six
  7. Wait some appropriate period of time
  8. Remove the EMF exporter

@aateeqi can you please ensure that there is an issue that documents the high-level plan and the steps involved?

This is a very large PR @aateeqi ,

Please consider breaking this down into smaller PRs

Perhaps, though I think the bulk of it is in the internal/aws/cloudwatch module, which is being extracted from the EMF exporter. Extracting it and using it in the CW exporter could perhaps be separated, but the use in the CW exporter is a small fraction of the LOC here and combining them provides actual use of the newly extracted module as validation of its correctness.

@MovieStoreGuy
Copy link
Contributor

That makes a bit more sense @Aneurysm9 ,

There was a lot that was changing so it was hard to rationalise what was a lift and shift, and what was new behaviour.
It didn't help that the three reference tickets are loosely related to changes going on here.

+1 on an issue describing the changes, it simply helps me review and understand what is the expected behaviour and end state just to help validate it does what is expected.

If it is also not too much to ask, a link to any public references would also be appreciated to help understand the changes.

I feel like I am asking for a lot but I would like to make sure I understand in enough detail to help get these changes through.

@aateeqi
Copy link
Contributor Author

aateeqi commented Dec 30, 2021

Hey @MovieStoreGuy, thanks for taking a look at the PR and leaving some insightful comments and @Aneurysm9 for also explaining some of the high level plan. The PR is still in draft stage and was published mainly for visibility and I generally agree with whats being said and will be continually updating.

@MovieStoreGuy
Copy link
Contributor

It is honestly a pleasure @aateeqi ,

I am very happy to review things and help if needed. If you'd like any further reviews, just ping me and I shall check it within the day (timezone nonsense and all that).

Happy and safe holidays to you.

@aateeqi aateeqi changed the title Enhance awscloudwatchlogs exporter Extract CWlogs client from EMF exporter and use in Awscloudwatchlogsexporter Jan 3, 2022
@anuraaga
Copy link
Contributor

anuraaga commented Jan 4, 2022

This PR seems to be hard to review since it's doing it in the wrong order. We should "Extract CWlogs client from EMF exporter and use in awsemfexporter". This is "Copy CWLogs client from EMF exporter to internal and use in logs exporter". It causes all of the pusher related code to be treated as new files instead of moved code. Additionally, we can't gauge the impact this change will have on the emf exporter, which is actually the more important component when extracting code from it. Can we close this PR and start with the emfexporter instead?

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.

4 participants