Documentation ¶
Index ¶
- Variables
- func CheckAIManager(aiMgr *AIManager) error
- func ExtractSelectSQL(sql string) string
- func IsInvalidQuery(sql string) bool
- type AIManager
- func (a *AIManager) ConvertTextToSQL(query string) (string, error)
- func (a *AIManager) DiagnoseEvents(ctx context.Context, events []Event, language string, ...) error
- func (a *AIManager) DiagnoseLogs(ctx context.Context, logs []string, language string, ...) error
- func (a *AIManager) DiagnoseLogsHandler(ctx context.Context, logs []string, language string, w http.ResponseWriter)
- func (a *AIManager) FixSQL(sql string, query string, sqlErr string) (string, error)
- func (a *AIManager) InterpretIssues(ctx context.Context, auditData *AuditData, language string, ...) error
- func (a *AIManager) InterpretYAML(ctx context.Context, yaml, language string, eventChan chan<- *InterpretEvent) error
- type AuditData
- type DiagnosisEvent
- type Event
- type InterpretEvent
- type IssueGroup
- type PromptType
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingAuthToken = errors.New("auth token is required") ErrInvalidQuery = errors.New("query is invalid") )
var ServicePromptMap = map[PromptType]string{ DefaultType: "You are a helpful assistant.", Text2sqlType: `You are an AI specialized in writing SQL queries. Please convert the text: "%s" to sql. If the text is not accurate enough, please output "Error". The output tokens only need to give the SQL first, the other thought process please do not give. The SQL should begin with "select * from" and end with ";". 1. The database now only supports one table resources. Table resources, columns = [cluster, apiVersion, kind, namespace, name, creationTimestamp, deletionTimestamp, ownerReferences, resourceVersion, labels.[key], annotations.[key], content] 2. find the schema_links for generating SQL queries for each question based on the database schema. If there are Chinese expressions, please translate them into English. Follow are some examples. Q: find the kind which is not equal to pod A: Let's think step by step. In the question "find the kind column which is not equal to pod", we are asked: "find the kind" so we need column = [kind]. Based on the columns, the set of possible cell values are = [pod]. So the Schema_links are: Schema_links: [kind, pod] Q: find the kind Deployment which created before January 1, 2024, at 18:00:00 A: Let's think step by step. In the question "find the kind Deployment which created before January 1, 2024, at 18:00:00", we are asked: "find the kind Deployment" so we need column = [kind]. "created before" so we need column = [creationTimestamp]. Based on the columns, the set of possible cell values are = [Deployment, 2024-01-01T18:00:00Z]. So the Schema_links are: Schema_links: [[kind, Deployment], [creationTimestamp, 2024-01-01T18:00:00Z]] Q: find the kind Namespace which which created A: Let's think step by step. In the question "find the kind", we are asked: "find the kind Namespace " so we need column = [kind] "created before" so we need column = [creationTimestamp] Based on the columns, the set of possible cell values are = [kind, creationTimestamp]. There is no creationTimestamp corresponding cell values, so the text is not accurate enough. So the Schema_links are: Schema_links: error 3. Use the the schema links to generate the SQL queries for each of the questions. Follow are some examples. Q: find the kind which is not equal to pod Schema_links: [kind, pod] SQL: select * from resources where kind!='Pod'; Q: find the kind Deployment which created before January 1, 2024, at 18:00:00 Schema_links: [[kind, Deployment], [creationTimestamp, 2024-01-01T18:00:00Z]] SQL: select * from resources where kind='Deployment' and creationTimestamp < '2024-01-01T18:00:00Z'; Q: find the namespace which does not contain banan Schema_links: [namespace, banan] SQL: select * from resources where namespace notlike 'banan_'; Q: find the kind Namespace which which created Schema_links: error Error; Please convert the text to sql.`, SQLFixType: `You are an AI specialized in writing SQL queries. Please convert the text: "%s" to sql. The SQL should begin with "select * from". The database now only supports one table resources. Table resources, columns = [cluster, apiVersion, kind, namespace, name, creationTimestamp, deletionTimestamp, ownerReferences, resourceVersion, labels.[key], annotations.[key], content] After we executed SQL: "%s", we observed the following error "%s". Please fix the SQL.`, LogDiagnosisType: `You are a Kubernetes log analysis expert. Your task is to analyze pod logs and provide a diagnosis in %s. Logs to analyze: %s Please provide: 1. A brief summary of any errors or issues found 2. The potential root cause of the problems 3. Recommended solutions or next steps 4. Any relevant Kubernetes best practices that could help prevent similar issues Note: Format your response with clear sections using markdown headings (##) and bullet points. Do NOT wrap your entire response in a markdown code block.`, EventDiagnosisType: `You are a Kubernetes expert specialized in diagnosing system and application issues through event analysis. Please analyze the following Kubernetes events and provide your diagnosis in %s. Events: %s Focus on: 1. Identify any issues or potential problems 2. Explain the root causes 3. Suggest specific solutions or preventive measures 4. Prioritize critical issues that need immediate attention Please structure your response with clear sections: 1. Summary of Issues 2. Detailed Analysis 3. Recommendations 4. Next Steps Note: Format your response with clear sections using markdown headings (##) and bullet points. Be specific and include technical details when relevant. Do NOT wrap your entire response in a markdown code block.`, YAMLInterpretType: `You are a Kubernetes YAML expert. Your task is to analyze and interpret the following YAML configuration and provide explanation in %s. YAML to interpret: %s Please provide a detailed analysis including: 1. Resource Type and Purpose - What kind of Kubernetes resource this is - The intended purpose and function of this resource 2. Key Configurations - Important settings and their implications (include line numbers in [Line X] format) - Default values and any custom configurations - Resource requirements and limits 3. Relationships and Dependencies - References to other resources (if any) - Required configurations or prerequisites - Service connections and networking details 4. Best Practices Analysis - Alignment with Kubernetes best practices - Security considerations - Performance implications - Potential improvements or optimizations 5. Potential Issues - Missing or misconfigured settings - Security concerns - Resource allocation issues - Common pitfalls to avoid Note: - When referencing specific configurations or values, always include their line numbers in brackets, e.g., [Line X] or [Line X-Y] - Format your response with clear sections using markdown headings (##) and bullet points - Do NOT wrap your entire response in a markdown code block - Use code blocks only for YAML examples or specific configuration snippets`, IssueInterpretType: `You are a Kubernetes expert specialized in analyzing security issues and providing solutions. Please analyze the following issues and provide your insights in %s. Issues Summary: %s Please provide a concise analysis focusing on: 1. Brief summary of the most critical issues (1-2 sentences) 2. Detailed solutions with specific examples, including: - Exact code or configuration changes needed - Before and after examples - Common pitfalls to avoid 3. Best practices and preventive measures Note: Format your response with clear sections using markdown headings (##) and bullet points. Do NOT wrap your entire response in a markdown code block.`, }
Functions ¶
func CheckAIManager ¶
CheckAIManager check if the AI manager is created
func ExtractSelectSQL ¶
ExtractSelectSQL extracts SQL statements that start with "SELECT * FROM"
func IsInvalidQuery ¶
IsInvalidQuery check if the query is invalid
Types ¶
type AIManager ¶
type AIManager struct {
// contains filtered or unexported fields
}
func NewAIManager ¶
func NewAIManager(c registry.ExtraConfig) (*AIManager, error)
NewAIManager returns a new AIManager object
func (*AIManager) ConvertTextToSQL ¶
ConvertTextToSQL converts natural language text to an SQL query
func (*AIManager) DiagnoseEvents ¶ added in v0.5.9
func (a *AIManager) DiagnoseEvents(ctx context.Context, events []Event, language string, eventChan chan<- *DiagnosisEvent) error
DiagnoseEvents analyzes Kubernetes events using LLM and returns diagnostic information through a streaming channel
func (*AIManager) DiagnoseLogs ¶ added in v0.5.9
func (a *AIManager) DiagnoseLogs(ctx context.Context, logs []string, language string, eventChan chan<- *DiagnosisEvent) error
DiagnoseLogs analyzes pod logs using LLM and returns diagnostic information through a streaming channel
func (*AIManager) DiagnoseLogsHandler ¶ added in v0.5.9
func (a *AIManager) DiagnoseLogsHandler(ctx context.Context, logs []string, language string, w http.ResponseWriter)
DiagnoseLogsHandler handles the HTTP streaming response for log diagnosis
func (*AIManager) InterpretIssues ¶ added in v0.6.0
func (a *AIManager) InterpretIssues(ctx context.Context, auditData *AuditData, language string, eventChan chan<- *InterpretEvent) error
InterpretIssues performs AI interpretation of scanner issues and sends events through the channel
func (*AIManager) InterpretYAML ¶ added in v0.5.9
func (a *AIManager) InterpretYAML(ctx context.Context, yaml, language string, eventChan chan<- *InterpretEvent) error
InterpretYAML performs AI interpretation of YAML content and sends events through the channel
type AuditData ¶ added in v0.6.0
type AuditData struct { IssueTotal int `json:"issueTotal"` ResourceTotal int `json:"resourceTotal"` BySeverity map[string]int `json:"bySeverity"` IssueGroups []*IssueGroup `json:"issueGroups"` }
AuditData represents the aggregated data of scanner issues, including the original list of issues and their aggregated count based on title.
type DiagnosisEvent ¶ added in v0.5.9
type DiagnosisEvent struct { Type string `json:"type"` // Event type: start/chunk/error/complete Content string `json:"content"` // Event content }
DiagnosisEvent represents a diagnosis streaming event
type Event ¶ added in v0.5.9
type Event struct { Type string `json:"type"` Reason string `json:"reason"` Message string `json:"message"` Count int32 `json:"count"` LastTimestamp string `json:"lastTimestamp"` FirstTimestamp string `json:"firstTimestamp"` }
Event represents a Kubernetes event for diagnosis
type InterpretEvent ¶ added in v0.5.9
type InterpretEvent struct { Type string `json:"type"` // Event type: start, chunk, error, complete Content string `json:"content,omitempty"` // Event content or error message }
InterpretEvent represents a single event in the YAML interpretation stream
type IssueGroup ¶ added in v0.6.0
type IssueGroup struct { Issue scanner.Issue `json:"issue"` ResourceGroups []entity.ResourceGroup `json:"resourceGroups"` }
IssueGroup represents a group of resourceGroups tied to a specific issue.
type PromptType ¶ added in v0.5.9
type PromptType string
PromptType represents the type of prompt to be used
const ( // DefaultType represents the default prompt type DefaultType PromptType = "default" // Text2sqlType represents the prompt type for text to SQL conversion Text2sqlType PromptType = "text2sql" // SQLFixType represents the prompt type for SQL fix SQLFixType PromptType = "sqlfix" // LogDiagnosisType represents the prompt type for log diagnosis LogDiagnosisType PromptType = "log_diagnosis" // EventDiagnosisType represents the prompt type for event diagnosis EventDiagnosisType PromptType = "event_diagnosis" // YAMLInterpretType represents the prompt type for YAML interpretation YAMLInterpretType PromptType = "yaml_interpret" // IssueInterpretType represents the prompt type for issue interpretation IssueInterpretType PromptType = "issue_interpret" )