From a270f7c89fb8bec35984715c5e4d160a2307e678 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Tue, 28 Mar 2023 10:43:12 +0100 Subject: [PATCH] feat: enables overwriting of cache (#95) --- cmd/analyze/analyze.go | 4 +++- pkg/analyzer/analyzer.go | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/analyze/analyze.go b/cmd/analyze/analyze.go index d9607d4c90..bd924d403c 100644 --- a/cmd/analyze/analyze.go +++ b/cmd/analyze/analyze.go @@ -22,6 +22,7 @@ var ( output string filters []string language string + nocache bool ) // AnalyzeCmd represents the problems command @@ -101,7 +102,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 @@ -135,6 +136,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)") diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index 3501071699..1bfde58d7e 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -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 { @@ -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 == "" {