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: use a cache file name with a fixed size. #350

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

matthisholleville
Copy link
Contributor

Closes #348

📑 Description

Our current caching method creates a file with the following pattern:

$BACKEND_AI-$LANG-$SENC

SENC corresponds to a base64 encoding of the errors detected on an object during analysis.

This approach fails when we have multiple errors reported for the same object. The base64 string becomes too long, resulting in the following error:

error storing value to cache: open /Users/matthisholleville/Library/Caches/k8sgpt/openai-english-SW5ncmVzcyBrOHNncHQvZmFrZS1pbmdyZXNzIGRvZXMgbm90IHNwZWNpZnkgYW4gSW5ncmVzcyBjbGFzcy4gSW5ncmVzcyB1c2VzIHRoZSBzZXJ2aWNlIGs4c2dwdC9mYWtlLXNlcnZpY2Ugd2hpY2ggZG9lcyBub3QgZXhpc3QuIEluZ3Jlc3MgdXNlcyB0aGUgc2VjcmV0IGs4c2dwdC9mYWtlLXNlY3JldCBhcyBhIFRMUyBjZXJ0aWZpY2F0ZSB3aGljaCBkb2VzIG5vdCBleGlzdC4=: file name too long

To address this issue, we use SHA256 to encode filename and keep fixe file name size

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

ℹ Additional Information

I have also fixed another bug related to the no-cache feature. Previously, when we activated no-cache, the cache was not used, but the command result was not updated either. This resulted in bugs like the following:

$ k8sgpt analyze --explain

0 k8sgpt/fake-hpa(fake-hpa)
Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist.
Fake

$ k8sgpt analyze --explain --no-cache

0 k8sgpt/fake-hpa(fake-hpa)
Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist.
The HorizontalPodAutoscaler is trying to scale a StatefulSet/fake-deployment, which does not exist.

$ k8sgpt analyze --explain

0 k8sgpt/fake-hpa(fake-hpa)
Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist.
Fake

I have fixed this issue so that when the --no-cache option is enabled, the cache is not used, but it is updated with the latest response.

@matthisholleville matthisholleville requested review from a team as code owners April 27, 2023 06:57
@matthisholleville matthisholleville changed the title fix: Use a cache file name with a fixed size. fix: use a cache file name with a fixed size. Apr 27, 2023
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
@thschue
Copy link
Contributor

thschue commented Apr 27, 2023

For me, this looks good ...

@AlexsJones : What do you think?

Copy link
Contributor

@thschue thschue left a comment

Choose a reason for hiding this comment

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

lgtm

@thschue thschue merged commit dee4235 into k8sgpt-ai:main Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

question: Unable to create a cache file
3 participants