k8sgpt-ai / k8sgpt-operator

Automatic SRE Superpowers within your Kubernetes cluster
https://k8sgpt.ai
Apache License 2.0
276 stars 73 forks source link

feature: add interval on AI backend request #426

Open VaibhavMalik4187 opened 2 months ago

VaibhavMalik4187 commented 2 months ago

📑 Description

This commit introduces the ability to send the requests to the backend AI server at set intervals, independent of the reconciler's requeue requests.

To utilize this feature, the Interval field in the AI settings must be set in the k8sgpt configuration object. Also, the specified interval must be greater than or equal to the reconciler's requeue interval as the llm requests should be called after the reconciler executes k8sgpt analyze.

Fixes: https://github.com/k8sgpt-ai/k8sgpt-operator/issues/419

✅ Checks

VaibhavMalik4187 commented 2 months ago

@AlexsJones, @JuHyung-Son, where do we intend to use the responses obtained from repeatedly calling the AI backend?

JuHyung-Son commented 2 months ago

what do you mean repeatedly calling the AI backend ?

VaibhavMalik4187 commented 2 months ago

what do you mean repeatedly calling the AI backend ?

Sorry if it's a naive question, I referred to the results obtained when the AI backend is called outside the reconciler loop (at set intervals). How do we plan to use them?

JuHyung-Son commented 2 months ago

I'm sorry, but I don't think I understand the situation very well. what is the situation that ai backend is called outside the reconciler loop? do we have that situation?

VaibhavMalik4187 commented 2 months ago

I'm sorry, but I don't think I understand the situation very well. what is the situation that ai backend is called outside the reconciler loop? do we have that situation?

No problem, I'll try again. So we're working on this feature to support calling the AI backend at set intervals independent of the reconciler loop.

I approached this feature in the following manner:

  1. Check if the user has set the k8sgptConfig.Spec.AI.Interval field and its duration is greater than k8sgptClient.ProcessAnalysis(k8sgptConfig, allowBackendAIRequest). If yes, then call repeatBackendRequest.
  2. repeatBackendRequest will call time.AfterFunc to call k8sgptClient.ProcessAnalysis(k8sgptConfig, allowBackendAIRequest) and obtain the results outside the reconciler loop at set intervals.
  3. At this step, we'll have the response obtained from the AI backend.
  4. What to do next??