mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-23 18:08:17 +00:00
* fix: stop execution after matching condition in RunAnalysis() The commit fixes the issue where the RunAnalysis() function continues execution even after matching a condition. The fix ensures that the execution stops at the end of the corresponding if statement, improving the control flow and preventing unnecessary processing. Signed-off-by: Matthis Holleville <matthish29@gmail.com> * feat: include filters parameter in AnalyzeRequest initialization The commit introduces a new feature where the filters parameter is included in the initialization of the AnalyzeRequest. This enhancement allows for more specific analysis by specifying filters during the analysis process. Signed-off-by: Matthis Holleville <matthish29@gmail.com> --------- Signed-off-by: Matthis Holleville <matthish29@gmail.com>
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
json "encoding/json"
|
|
|
|
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
|
|
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/analysis"
|
|
)
|
|
|
|
type handler struct {
|
|
rpc.UnimplementedServerServer
|
|
}
|
|
|
|
func (h *handler) Analyze(ctx context.Context, i *schemav1.AnalyzeRequest) (
|
|
*schemav1.AnalyzeResponse,
|
|
error,
|
|
) {
|
|
if i.Output == "" {
|
|
i.Output = "json"
|
|
}
|
|
|
|
if i.Backend == "" {
|
|
i.Backend = "openai"
|
|
}
|
|
|
|
if int(i.MaxConcurrency) == 0 {
|
|
i.MaxConcurrency = 10
|
|
}
|
|
|
|
config, err := analysis.NewAnalysis(
|
|
i.Backend,
|
|
i.Language,
|
|
i.Filters,
|
|
i.Namespace,
|
|
i.Nocache,
|
|
i.Explain,
|
|
int(i.MaxConcurrency),
|
|
)
|
|
if err != nil {
|
|
return &schemav1.AnalyzeResponse{}, err
|
|
}
|
|
config.RunAnalysis()
|
|
|
|
if i.Explain {
|
|
err := config.GetAIResults(i.Output, i.Anonymize)
|
|
if err != nil {
|
|
return &schemav1.AnalyzeResponse{}, err
|
|
}
|
|
}
|
|
|
|
out, err := config.PrintOutput(i.Output)
|
|
if err != nil {
|
|
return &schemav1.AnalyzeResponse{}, err
|
|
}
|
|
var obj schemav1.AnalyzeResponse
|
|
|
|
err = json.Unmarshal(out, &obj)
|
|
if err != nil {
|
|
return &schemav1.AnalyzeResponse{}, err
|
|
}
|
|
|
|
return &obj, nil
|
|
}
|