Skip to content

Conversation

florianl
Copy link
Member

Initialize local variable only once and make sure expected APMData is handled first.

@github-actions github-actions bot added the aws-λ-extension AWS Lambda Extension label Oct 25, 2024
// with any encoding format
ErrInvalidEncoding = errors.New("encoded data not supported")
// ErrNoData indicates that APMData.data is empty
ErrNoData = errors.New("no data")
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this, no data is not an error for the batch and I don't like returning no data errors. Now that we have already handled no data case in ForwardAPMData, can we remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

What is your suggestion to return for thelen(apmData.Data) == 0 case in AddAgentData()?
Just because there is a check in ForwardAPMData() does not prevent other users of AddAgentData() running into this issue.

Copy link
Contributor

@lahsivjar lahsivjar Oct 25, 2024

Choose a reason for hiding this comment

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

My point is that for the batch having an empty data is not an error. The batch can just not add data in this case. If we want to protect against edge cases we should do it at the source (like how we do in ForwardAPMData).

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if we want to be more specific in handling the behaviour, we could introduce another method in the batch to check the metadata status, something like bool HasMetadata() and incorporate it where we require such a check.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still consider the use case len(apmData.Data) == 0 in AddAgentData() dangerous even if the only caller atm ™️ is using a check. What makes this package and its API safe to use, if something else calls AddAgentData()?
Even if no data is considered a non error case, what should it be considered instead and how should it be treated? With the current behavior it seems to run into issues.

we could introduce another method in the batch to check the metadata status, something like bool HasMetadata() and incorporate it where we require such a check.

If AddAgentData() implements such a check, what should be returned in a case where

  • there is not metadata but len(apmData.Data) != 0. Is in this case data loss the expected result?
  • there is metadata but len(apmData.Data) == 0

Copy link
Contributor

Choose a reason for hiding this comment

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

What makes this package and its API safe to use, if something else calls AddAgentData()?

Agent data here refers to data from the APM agents and intake-v2 is the only supported protocol. What other cases do you have in mind here?

there is not metadata but len(apmData.Data) != 0. Is in this case data loss the expected result?

If data from the agent is not nil then it MUST have the metadata as the first line.

there is metadata but len(apmData.Data) == 0

apmData.Data is including the metadata so this is also not possible. We could have only metadata in the body and that is okay.

Copy link
Member

Choose a reason for hiding this comment

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

@lahsivjar So essentially in your view, ErrNoData and associated logic is redundant as "no data" can take place during normal operation, and if we want to check for this case, we should do it before calling AddAgentData. Is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, yes! I don't have a strong opinion here so feel free to ignore it.

Copy link
Member

@christos68k christos68k left a comment

Choose a reason for hiding this comment

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

I think the fix that @florianl implements in this PR (not exiting the processing loop when len(data.Data) == 0) is important and should be merged. @lahsivjar Do we need anything else to get this merged?

// with any encoding format
ErrInvalidEncoding = errors.New("encoded data not supported")
// ErrNoData indicates that APMData.data is empty
ErrNoData = errors.New("no data")
Copy link
Member

Choose a reason for hiding this comment

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

@lahsivjar So essentially in your view, ErrNoData and associated logic is redundant as "no data" can take place during normal operation, and if we want to check for this case, we should do it before calling AddAgentData. Is that correct?

@lahsivjar
Copy link
Contributor

lahsivjar commented Oct 30, 2024

Do we need anything else to get this merged?

I think with sync.Once to nil check we should be good to merge. The remaining point on the ErrNoData is not that important and we can ignore it if it doesn't make sense to others.

@florianl florianl merged commit 0ca92fe into main Nov 1, 2024
8 checks passed
@florianl florianl deleted the flo-no-data-error branch November 1, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-λ-extension AWS Lambda Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants