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

feat: prefix k8s attributes with source and add more k8s destination attributes #226

Merged
merged 11 commits into from
Sep 25, 2023

Conversation

JamieDanielson
Copy link
Contributor

@JamieDanielson JamieDanielson commented Sep 21, 2023

Which problem is this PR solving?

Short description of the changes

  • Add source. prefix to k8s pod name and uid to more easily differentiate from destination pod name and uid
  • Mirror the source attributes to the destination attributes

How to verify that this has the expected result

Events include the new attributes and it's easier to differentiate source from destination.

@JamieDanielson JamieDanielson requested a review from a team September 21, 2023 18:36
@JamieDanielson JamieDanielson changed the title Jamie.add source prefix feat: prefix k8s attributes with source and add more k8s destination attributes Sep 21, 2023
@JamieDanielson JamieDanielson self-assigned this Sep 21, 2023
@JamieDanielson JamieDanielson added the type: enhancement New feature or request label Sep 21, 2023
@JamieDanielson
Copy link
Contributor Author

I couldn't recall if there was some reason why we didn't have the same attributes for destination, so I added them all here. Because these are done as 3 separate commits, we could easily just keep the first one that adds source to the pod name and uid (if indeed we were intentionally omitting destination). The second commit adds mirrored attributes and the third just refactors.

Base automatically changed from robb.update-semconv to main September 21, 2023 20:38
@JamieDanielson
Copy link
Contributor Author

Spending a bit of time working on tests for this!

@JamieDanielson JamieDanielson marked this pull request as draft September 21, 2023 22:06
@JamieDanielson
Copy link
Contributor Author

@robbkidd was going to poke at tests a bit since I'll be out for a few days - timebox and if it's too cumbersome we should remove the fake cached client and merge without tests for this for now.

kubernetes.Clientset and fake.Clientset both implement the interface.
Change the param type on this function and we won't need a separate
FakeCacheK8sClient implementation.
In the previous implementation, only the destination IP would be looked
up. Instead, make the function generic to lookup k8s metadata based on
IP and provide an optional prefix for the attribute names set.

TESTS! For the k9s metadata, too!
To remember how to hold this thing for testing.
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looking great. Added one suggestion for adding wrapper functions over GetK8sAttrsForIp.

// Provide a prefix to prepend to the attribute names, example: "source" or "destination".
//
// If the IP address is not found in the kubernetes cache, an empty map is returned.
func GetK8sAttrsForIp(client *CachedK8sClient, ip string, prefix string) map[string]any {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about offer two wrapping funcs, GetK8sAttrsForSourceIP and GetK8sAttrsForDestinationIP, which include the "source" and "destination" prefixes?

It would simplify users to just call the correct func instead of knowing what prefix to use.

Copy link
Member

Choose a reason for hiding this comment

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

Added in 3dcf19a. Whad'ya think?

@MikeGoldsmith MikeGoldsmith marked this pull request as ready for review September 25, 2023 13:48
We're always looking up a source or destination IP at the moment, so
provide specific functions for that. They wrap the generic k8s attribute
lookup and prefixer to avoid duplicating implementation. Also, we might
have other IPs to lookup and prefix differently in the future.
@robbkidd robbkidd merged commit 2317ce4 into main Sep 25, 2023
3 checks passed
@robbkidd robbkidd deleted the jamie.add-source-prefix branch September 25, 2023 19:01
robbkidd added a commit that referenced this pull request Sep 25, 2023
## Which problem is this PR solving?
Refactors event processing into an handlers package. This enables better
testing of libhoney event processing.

## Short description of the changes
- Move libhoney event processing into new handlers package as
libhoney_event_handler
- Move main_test.go to handlers package as libhoney_event_handler_test
- Update libhoney test to use ctx, done pattern and pass in test event
via the event channel
- Refactor main.go to create handler and connect up events channel
- Update TCP assembler to use ctx.Done() in processing loop to handle
shutdown

## How to verify that this has the expected result
Nothing external. The agent should continue to work as it is. This is a
refactor PR to make maintenance easier going forward.

**NOTE**: This PR is based on the branch in the following PR:
- #226

---------

Co-authored-by: JamieDanielson <jamieedanielson@gmail.com>
Co-authored-by: Robb Kidd <robbkidd@honeycomb.io>
robbkidd added a commit that referenced this pull request Sep 25, 2023
## Which problem is this PR solving?
The cached k8s client has lookup functions to aid with providing more
context to events being sent. The lookup functions are inefficient
because they loop over all the available data until it finds something
it thinks is correct, but may not be.

The PR refactors three functions to use better lookup strategies which
are both faster and more accurate.

- Closes #223 

## Short description of the changes-
- Create a managed index on the pod informer that uses the pod's IP as
the key
- Update GetPodByIPAddr to use new pod index
- Create a managed index on the node informer that uses the node's name
as the key
- Update GetNodeForPod to new use node index
- Refactor GetServiceForPod to loop through registered services and
applies it's selector against the given pod's labels

## How to verify that this has the expected result
Lookup functions using the cached k8s client are both faster and more
accurate.

**NOTE**: This PR is based on the branch in the following PR:
- #226

---------

Co-authored-by: JamieDanielson <jamieedanielson@gmail.com>
Co-authored-by: Robb Kidd <robbkidd@honeycomb.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prefix source with source (similar to destination prefixed with destination)
3 participants