Skip to content

OB-34960 Decorate k8s Node facets with custom processors #74

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

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

obs-gh-enricogiorio
Copy link
Collaborator

@obs-gh-enricogiorio obs-gh-enricogiorio commented Aug 15, 2024

Add "Status" and "Roles" facets

Rework the testing a bit to allow using jmespath to query specific fields of interest instead of manually creating json-like objects in go to exactly match the output.

Description

This PR adds the "Roles" and "Status" facets to Node.
Since "Roles" is an array, I had to change the interface of the existing ValueFn() to return any instead of string, so that we can return maps and arrays, too.

The current testing process is a bit cumbersome and doesn't scale well, since we are making a single pcommon.Logs containing all testing input logs, and then we have to maintain a parallel slice of "desired outputs", correlating inLogs[i] with outResults[i]. Since the correlation is always 1:1, I figured I could change this to:
each testcase contains a single pcommon.Logs, which contains only ONE Log. And each testcase also contains whatever verification(s) we want for the processed output of such log. Then we simply iterate over the testcases.
I also got rid of all manually-created map[string]interface{} json-like madness and used jmespath, which allows for simpler and more powerful queries, so that we can selectively test what we need from the processed Logs!
Given that we don't do correlation between logs, I figured that the assumption of always having a single log both as input and as output of the processor is enough for what we are doing here.

Checklist

  • Created tests which fail without the change (if possible) --> not possible, this is modular
  • Extended the README / documentation, if necessary

Add "Status" and "Roles" facets

Rework the testing a bit to allow using jmespath to query specific
fields of interest instead of manually creating json-like objects in go
to exactly match the output.
@obs-gh-enricogiorio
Copy link
Collaborator Author

I pushed a 2nd commit because I didn't know it would fall into the same PR, I thought it was gonna work the same as gerrit. If that's ok for you, we can leave it as-is and merge both together (it kinda makes sense as the second commit depends on the refactorings I made in the first one).

Add a single custom processor that generates 3 facets:
- restarts
- ready_containers
- total_containers

The reasoning behind a single-processor for multiple facets is that all
of these 3 facets are computed by iterating the same slice. Computing
them in 3 different actions means iterating the same slice 3 times.
@obs-gh-enricogiorio obs-gh-enricogiorio force-pushed the enrico/nodeFacets branch 2 times, most recently from 49093a6 to 156db7d Compare August 15, 2024 18:14
facetsMap.EnsureCapacity(facetsMap.Len() + len(values))
for key, val := range values {
if err := mapPut(facetsMap, key, val); err != nil {
return logs, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we give up when we hit an error and return the logs in the current state? or should we just skip that action and continue

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha good catch. Let's continue instead of aborting the whole thing!

kubectl generates readinessGates as "0/1", "1/2", "2/2" (string).
This may not be ideal for us, as we might want to do
computation/aggregation on these columns separately.

Therefore, we provide two (numeric) facets (from the same action):

 - readinessGatesReady
 - readinessGatesTotal
@obs-gh-enricogiorio obs-gh-enricogiorio merged commit 0099f34 into main Aug 15, 2024
8 checks passed
@obs-gh-enricogiorio obs-gh-enricogiorio deleted the enrico/nodeFacets branch August 15, 2024 20:20
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.

2 participants