mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-04-27 11:11:31 +00:00
adding performance optimisation through local caching
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
This commit is contained in:
parent
5d956e209f
commit
e4f138dc00
@ -6,7 +6,7 @@
|
||||
AI Powered Kubernetes debugging for SRE, Platform and DevOps teams.
|
||||
<br />
|
||||
|
||||
<img src="images/demo.gif" width=650px; />
|
||||
<img src="images/demo2.gif" width=650px; />
|
||||
|
||||
## What is k8sgpt?
|
||||
|
||||
|
BIN
images/demo2.gif
Normal file
BIN
images/demo2.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 KiB |
@ -2,6 +2,7 @@ package analyzer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -10,6 +11,7 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||
"github.com/spf13/viper"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
@ -50,20 +52,51 @@ func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient *ai.Cl
|
||||
}
|
||||
|
||||
}
|
||||
for key, value := range brokenPods {
|
||||
fmt.Printf("%s: %s\n", color.YellowString(key), color.RedString(value[0]))
|
||||
|
||||
count := 0
|
||||
for key, value := range brokenPods {
|
||||
fmt.Printf("%s: %s: %s\n", color.CyanString("%d", count), color.YellowString(key), color.RedString(value[0]))
|
||||
count++
|
||||
if explain {
|
||||
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond) // Build our new spinner
|
||||
s.Start()
|
||||
|
||||
response, err := aiClient.GetCompletion(ctx, strings.Join(value, " "))
|
||||
s.Stop()
|
||||
if err != nil {
|
||||
return err
|
||||
inputValue := strings.Join(value, " ")
|
||||
|
||||
// Check for cached data
|
||||
sEnc := base64.StdEncoding.EncodeToString([]byte(inputValue))
|
||||
// find in viper cache
|
||||
if viper.IsSet(sEnc) {
|
||||
s.Stop()
|
||||
// retrieve data from cache
|
||||
response := viper.GetString(sEnc)
|
||||
if response == "" {
|
||||
color.Red("error retrieving cached data")
|
||||
continue
|
||||
}
|
||||
output, err := base64.StdEncoding.DecodeString(response)
|
||||
if err != nil {
|
||||
color.Red("error decoding cached data: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
color.Green(string(output))
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", color.GreenString(response))
|
||||
response, err := aiClient.GetCompletion(ctx, inputValue)
|
||||
s.Stop()
|
||||
if err != nil {
|
||||
color.Red("error getting completion: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !viper.IsSet(sEnc) {
|
||||
viper.Set(sEnc, base64.StdEncoding.EncodeToString([]byte(response)))
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user