(ctx context.Context)
| 342 | } |
| 343 | |
| 344 | func (a *Adapter) Health(ctx context.Context) error { |
| 345 | path := strings.TrimSpace(a.cfg.HealthPath) |
| 346 | if path == "" { |
| 347 | if a.vertex { |
| 348 | proj := strings.TrimSpace(a.cfg.VertexProject) |
| 349 | loc := strings.TrimSpace(a.cfg.VertexLocation) |
| 350 | path = fmt.Sprintf("/v1/projects/%s/locations/%s", proj, loc) |
| 351 | } else { |
| 352 | path = "/v1beta/models" |
| 353 | } |
| 354 | } |
| 355 | if !strings.HasPrefix(path, "/") { |
| 356 | path = "/" + path |
| 357 | } |
| 358 | url := a.baseURL + path |
| 359 | httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) |
| 360 | if err != nil { |
| 361 | return err |
| 362 | } |
| 363 | a.applyAPIKey(httpReq) |
| 364 | a.applyExtraHeaders(httpReq) |
| 365 | resp, err := a.httpClient.Do(httpReq) |
| 366 | if err != nil { |
| 367 | return upstream.New(upstream.KindBackendUnhealthy, err.Error()) |
| 368 | } |
| 369 | defer resp.Body.Close() |
| 370 | if resp.StatusCode < 200 || resp.StatusCode >= 300 { |
| 371 | return upstream.New(upstream.KindBackendUnhealthy, fmt.Sprintf("gemini health failed status=%d path=%s", resp.StatusCode, path)) |
| 372 | } |
| 373 | return nil |
| 374 | } |
| 375 | |
| 376 | func (a *Adapter) applyAPIKey(req *http.Request) { |
| 377 | if k := a.apiKey(); k != "" { |
nothing calls this directly
no test coverage detected