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

fix: set partial message metadata flags in log events #24

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

PettitWesley
Copy link
Contributor

@PettitWesley PettitWesley commented Apr 15, 2022

Signed-off-by: Wesley Pettit wppttt@amazon.com

Issue #, if available:

#23
aws/containers-roadmap#1550

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@PettitWesley
Copy link
Contributor Author

CI is failing but I believe this is because it was not setup correctly: #25 (comment)

Copy link
Contributor

@JoseVillalta JoseVillalta left a comment

Choose a reason for hiding this comment

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

These changes LGTM however, I'd like to run an End to End test on Fargate to validate this behavior. Maybe add a Functional test as well?

@PettitWesley
Copy link
Contributor Author

@JoseVillalta Sure, pinged you with that CR

@aaithal
Copy link
Member

aaithal commented Apr 19, 2022

Can you please update the PR to have more documentation about what the fix here is for and why are we making certain changes?

Both PR description and commit message are very scant on details. Also, the code comments are sparse as well.

It's hard to review these changes without that context.

logger/common.go Outdated Show resolved Hide resolved
logger/common.go Show resolved Hide resolved
logger/common.go Outdated Show resolved Hide resolved
logger/common.go Outdated Show resolved Hide resolved
@@ -334,6 +371,18 @@ func (l *Logger) Read(
}
}

// generateRandomID is based on Docker
// GenerateRandomID: https://github.com/moby/moby/blob/bca8d9f2ce0d63e1490692917cde6273bc288bad/pkg/stringid/stringid.go#L40
Copy link
Member

Choose a reason for hiding this comment

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

Why can we not just use that method? Why are we replicating it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is explained in my comment below this line... I can make it longer and more detailed to make it clearer. The Docker generate function does the rand generation in a loop, because it can't allow the ID to container only 0 - 9 (digits) because then it can't be used a container ID. We don't have that concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another reason to not import from docker is properly handling that error return in rand.Read

@PettitWesley
Copy link
Contributor Author

@aaithal Is this issue description sufficient: #23

Or do you require comments explaining it in the code itself? Do you want me to link the issue in the commit message?

@aaithal
Copy link
Member

aaithal commented Apr 19, 2022

What would make it easier for readers to review this would be if you include a description of how you're solving the issue in the commit message (and/or code comments). You can repurpose this comment that you wrote in #23 as well: #23 (comment)

@PettitWesley
Copy link
Contributor Author

@aaithal Updated for your comments/Thanks for reviewing.

logger/common_test.go Outdated Show resolved Hide resolved
@aaithal
Copy link
Member

aaithal commented Apr 19, 2022

looks much better, thanks! I have a minor comment.

@PettitWesley
Copy link
Contributor Author

PettitWesley commented Apr 20, 2022

Before we merge this, I want to run a test on my instance where I send it a very very large log, something like 10 MB, since the unit tests and functional tests and all of my previous real world tests all use logs denoted in KBs/bytes.

@garmikea
Copy link
Contributor

Hi @PettitWesley I have tested your changes by running the Fargate Agent with your updated ECS Shim Logger code, and I am seeing the partial_id, partial_last, partial_message, and partial_ordinal fields. Are there any other things I should be looking for to verify your code changes are working as expected?

@PettitWesley
Copy link
Contributor Author

@garmikea Awesome... if those fields are present then its working... the only thing is to check that they make sense, the partial ordinals are ordered from 1.. N and the Nth log line has partial_last marked true.

@PettitWesley
Copy link
Contributor Author

@garmikea there is also the negative case as well, that with small log lines these fields are not set.

I will finish my final testing with very large log lines (multiple MBs) in a moment and I will also check the negative case as well. I think we are almost good to go with this change...

@PettitWesley
Copy link
Contributor Author

@aaithal @JoseVillalta @garmikea I have completed manual test cases with the Fluent Bit implementation, it all works together: #23 (comment)

This patch correctly set the partial metadata fields on the docker message structure. In EC2/vanilla Docker, this happens in the docker code. Those flags are expected to set. The docker message structure is then passed to the underlying log driver implementation which decides what to do with it. So for awslogs driver code for example, it does not use the partial fields at all, it ignores them and just sends the actual log line:
https://github.com/moby/moby/blob/61404de7df1a6c75c2cbdc2c3ce226c95bebcaad/daemon/logger/awslogs/cloudwatchlogs.go#L601

Here is the relevant Docker code for setting these partial fields: https://github.com/moby/moby/blob/master/daemon/logger/copier.go#L114

The fix in this log driver wrapper is to set the partial fields correctly, but its still up to the underlying log driver implementation (which we import directly from the docker code base) to use or not use those fields.

Signed-off-by: Wesley Pettit <wppttt@amazon.com>
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
@JoseVillalta JoseVillalta merged commit ce3bac8 into aws:master Apr 21, 2022
if len(expectedPartialOrdinalSequence) > 0 && lines < len(expectedPartialOrdinalSequence) {
// check partial fields
require.Equal(t, expectedPartialOrdinalSequence[lines], msg.PLogMetaData.Ordinal)
if msg.PLogMetaData.Ordinal < lastPartialOrdinal {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you forgot to check that the partial field evaluates to true

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.

None yet

4 participants