Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/secscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
steps:
- name: Checkout Source
uses: actions/checkout@v6
if: ${{ github.actor != 'dependabot[bot]' }}
if: ${{ !github.repository.fork && github.actor != 'dependabot[bot]' }}
- name: Run Gosec Security Scanner
if: ${{ github.actor != 'dependabot[bot]' }}
if: ${{ !github.repository.fork && github.actor != 'dependabot[bot]' }}
uses: securego/gosec@v2.27.1
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-no-fail -fmt sarif -out results.sarif ./...'
- name: Upload SARIF file
if: ${{ github.actor != 'dependabot[bot]' }}
if: ${{ !github.repository.fork && github.actor != 'dependabot[bot]' }}
uses: github/codeql-action/upload-sarif@v4
with:
# Path to SARIF file relative to the root of the repository
Expand Down
2 changes: 1 addition & 1 deletion core/http/endpoints/localai/backend_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func BackendMonitorEndpoint(bm *monitoring.BackendMonitorService) echo.HandlerFu
return echo.NewHTTPError(400, "model query parameter is required")
}

resp, err := bm.CheckAndSample(model)
resp, err := bm.CheckAndSample(c.Request().Context(), model)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/http/endpoints/localai/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func LocalAIMetricsAPIMiddleware(metrics *monitoring.LocalAIMetricsService) echo
start := time.Now()
err := next(c)
elapsed := float64(time.Since(start)) / float64(time.Second)
cfg.metricsService.ObserveAPICall(method, path, elapsed)
cfg.metricsService.ObserveAPICall(c.Request().Context(), method, path, elapsed)
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/monitoring/backend_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (bms *BackendMonitorService) SampleLocalBackendProcess(model string) (*sche
}, nil
}

func (bms BackendMonitorService) CheckAndSample(modelName string) (*proto.StatusResponse, error) {
func (bms BackendMonitorService) CheckAndSample(ctx context.Context, modelName string) (*proto.StatusResponse, error) {
modelAddr := bms.modelLoader.CheckIsLoaded(modelName)
if modelAddr == nil {
return nil, fmt.Errorf("backend %s is not currently loaded", modelName)
}

status, rpcErr := modelAddr.GRPC(false, nil).Status(context.TODO())
status, rpcErr := modelAddr.GRPC(false, nil).Status(ctx)
if rpcErr != nil {
xlog.Warn("backend experienced an error retrieving status info", "backend", modelName, "error", rpcErr)
val, slbErr := bms.SampleLocalBackendProcess(modelName)
Expand Down
17 changes: 8 additions & 9 deletions core/services/monitoring/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package monitoring
import (
"context"

"github.com/mudler/xlog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/prometheus"
Expand All @@ -17,12 +16,12 @@ type LocalAIMetricsService struct {
ApiTimeMetric metric.Float64Histogram
}

func (m *LocalAIMetricsService) ObserveAPICall(method string, path string, duration float64) {
func (m *LocalAIMetricsService) ObserveAPICall(ctx context.Context, method string, path string, duration float64) {
opts := metric.WithAttributes(
attribute.String("method", method),
attribute.String("path", path),
)
m.ApiTimeMetric.Record(context.Background(), duration, opts)
m.ApiTimeMetric.Record(ctx, duration, opts)
}

// setupOTelSDK bootstraps the OpenTelemetry pipeline.
Expand Down Expand Up @@ -55,10 +54,10 @@ func NewLocalAIMetricsService() (*LocalAIMetricsService, error) {
}

func (lams LocalAIMetricsService) Shutdown() error {
// TODO: Not sure how to actually do this:
//// setupOTelSDK bootstraps the OpenTelemetry pipeline.
//// If it does not return an error, make sure to call shutdown for proper cleanup.

xlog.Warn("LocalAIMetricsService Shutdown called, but OTelSDK proper shutdown not yet implemented?")
return nil
// Shutdown flushes any pending telemetry held by the OTel MeterProvider
// and releases the Prometheus exporter. Without this call the process
// leaves counters and the reader in an inconsistent state on shutdown
// which matters for short-lived CLI subcommands (e.g. `local-ai mcp-server`)
// and for tests that spin up a fresh service per case.
return lams.Provider.Shutdown(context.Background())
}