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: enables overwriting of cache #95

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
output string
filters []string
language string
nocache bool
)

// AnalyzeCmd represents the problems command
Expand Down Expand Up @@ -100,7 +101,7 @@ var AnalyzeCmd = &cobra.Command{
for _, analysis := range *analysisResults {

if explain {
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error)
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error, nocache)
if err != nil {
color.Red("Error: %v", err)
continue
Expand Down Expand Up @@ -134,6 +135,7 @@ var AnalyzeCmd = &cobra.Command{

func init() {

AnalyzeCmd.Flags().BoolVarP(&nocache, "no-cache", "n", false, "Do not use cached data")
// array of strings flag
AnalyzeCmd.Flags().StringSliceVarP(&filters, "filter", "f", []string{}, "Filter for these analzyers (e.g. Pod,PersistentVolumeClaim,Service,ReplicaSet)")

Expand Down
8 changes: 5 additions & 3 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/spf13/viper"
)

func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {
func RunAnalysis(ctx context.Context, client *kubernetes.Client,
aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {

err := AnalyzePod(ctx, client, aiClient, explain, analysisResults)
if err != nil {
Expand All @@ -35,13 +36,14 @@ func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI
return nil
}

func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string) (string, error) {
func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string,
nocache bool) (string, error) {
// parse the text with the AI backend
inputKey := strings.Join(prompt, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
// find in viper cache
if viper.IsSet(sEnc) {
if viper.IsSet(sEnc) && !nocache {
// retrieve data from cache
response := viper.GetString(sEnc)
if response == "" {
Expand Down