Skip to content

feat(ai): add Google Gemini provider + improved error handling#166

Open
sivaangayarkanni wants to merge 2 commits into
optiqor:mainfrom
sivaangayarkanni:feat/gemini-provider-error-handling
Open

feat(ai): add Google Gemini provider + improved error handling#166
sivaangayarkanni wants to merge 2 commits into
optiqor:mainfrom
sivaangayarkanni:feat/gemini-provider-error-handling

Conversation

@sivaangayarkanni

@sivaangayarkanni sivaangayarkanni commented Jun 2, 2026

Copy link
Copy Markdown

What

Added Google Gemini as a new AI provider, introduced 3 new AI correlation patterns, and improved error handling with a structured LoadError type and helper functions.

Why

  • Users wanted native support for Google Gemini.
  • Current error messages when eBPF fails to load are not helpful.
  • AI analysis was missing useful cross-signal correlations.

Fixes #165

How

  • Added gemini.go and gemini_test.go with pure HTTP integration (no SDK).
  • Extended AI fallback logic in fallback.go with 3 new correlation patterns.
  • Created errors.go with LoadError type + helper functions (IsPermissionError, IsBTFError, IsVerifierError).
  • All changes include full test coverage and follow existing project style.

Testing

  • go build ./... passes
  • go test ./... passes
  • go vet ./... passes
  • golangci-lint run ./... passes
  • Tested locally with: sudo ./bin/kerno doctor --ai
  • N/A — pure docs/refactor
  • sudo ./bin/bpf-verify --read 5s confirms 6/6 programs still load
  • ./scripts/verify.sh passes (or specific phase: ./scripts/verify.sh quality)

Checklist

  • PR title follows Conventional Commits (feat(ai): add Google Gemini provider + improved error handling)
  • All commits are DCO-signed (git commit -s)
  • No unrelated changes pulled in
  • Documentation updated where user-visible behavior changed
  • Added/updated tests for new code paths
  • If a new doctor rule, paired with a chaos scenario in scripts/verify.sh

Add complete Google Gemini API integration as a new LLM provider:
- Implement GeminiProvider with HTTP-based API client
- Add comprehensive test suite with 7 test cases
- Update provider factory to support gemini provider
- Support configurable model, temperature, and max tokens
- Default to gemini-1.5-flash model

feat(bpf): add enhanced error handling with contextual hints

Add LoadError type and classification utilities:
- WrapLoadError() for enriching errors with context
- classifyLoadError() with 11+ error pattern mappings
- Helper functions: IsPermissionError, IsBTFError, IsVerifierError
- Actionable user-facing fix hints for common BPF load failures
- Complete test coverage with 20+ test cases

feat(ai): enhance correlation analysis with new patterns

Add 3 new correlation patterns to fallback analyzer:
- Memory + cgroup memory detection
- Scheduler + syscall correlation
- TCP + memory buffer exhaustion detection

Signed-off-by: Sivaangayarkanni <siva.21.baba@gmail.com>
@github-actions github-actions Bot added level:critical Touches BPF, security, or release surfaces (auto-applied) documentation Improvements or additions to documentation testing Tests and test coverage area/bpf eBPF programs and loaders area/integrations External integrations (sinks, exports, CI) labels Jun 2, 2026
@sivaangayarkanni sivaangayarkanni force-pushed the feat/gemini-provider-error-handling branch from 1abef82 to 37702d6 Compare June 2, 2026 17:24

@btwshivam btwshivam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the gemini provider is clean raw net/http, but ci is red and the PR carries unrelated changes: it rewrites the front-page readme (drops the comparison table and the k8s positioning, that GTM content is live on main, pull it out), and adds an unrelated internal/bpf/errors.go package. fix the ci failures and split the scope.

Comment thread internal/ai/fallback.go
}

// Scheduler + syscall → CPU contention causing syscall queueing.
if signals["sched"] && signals["syscall"] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these new correlation pairs are why TestDetectSimpleCorrelations/all_four_pairs fails (got 5, want 4), that's the red Test job. new correlation rules need the test updated in the same change, and this is separate from a gemini provider, split it out.

Comment thread internal/ai/gemini.go

type geminiRequest struct {
Contents []geminiContent `json:"contents"`
GenerationConfig geminiGenerationConfig `json:"generationConfig"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not gofmt-clean (double space before the struct tag), that's the red Lint job. run gofmt.

Comment thread internal/ai/gemini.go
}

// Build the URL with API key.
url := fmt.Sprintf("%s/models/%s:generateContent?key=%s",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the api key goes in the url query string, so it lands in any proxy or client request log. gemini accepts x-goog-api-key, send it as a header so the key stays out of the url.

Comment thread internal/ai/gemini.go
}, nil
}

// ─── Gemini API Types ───────────────────────────────────────────────────────

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

box-drawing section header and an em-dash in the comments, drop both per the comment style (plain lowercase, no decoration, no em-dash).

Comment thread internal/bpf/errors.go
// Copyright 2026 Optiqor contributors
// SPDX-License-Identifier: Apache-2.0

package bpf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a whole new bpf load-error package is unrelated to a gemini provider. pull it into its own PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/bpf eBPF programs and loaders area/integrations External integrations (sinks, exports, CI) documentation Improvements or additions to documentation level:critical Touches BPF, security, or release surfaces (auto-applied) testing Tests and test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add Google Gemini AI provider + enhanced error handling + new correlation patterns

2 participants