Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ go_library(
"//src/invocation-plane-services/llm-api-gateway/templating/prompt",
"@com_github_google_uuid//:uuid",
"@com_github_labstack_echo_v4//:echo",
"@com_github_nvidia_nvcf_src_libraries_go_lib//pkg/version",
"@com_github_rs_zerolog//:zerolog",
"@com_github_rs_zerolog//log",
"@io_opentelemetry_go_otel//:otel",
Expand All @@ -81,6 +82,7 @@ go_test(
srcs = [
"auth_middleware_test.go",
"embeddings_handler_test.go",
"info_test.go",
"middleware_telemetry_test.go",
"middleware_test.go",
"model_ids_test.go",
Expand All @@ -104,6 +106,7 @@ go_test(
"//src/invocation-plane-services/llm-api-gateway/requestctx",
"//src/invocation-plane-services/llm-api-gateway/telemetry",
"@com_github_labstack_echo_v4//:echo",
"@com_github_nvidia_nvcf_src_libraries_go_lib//pkg/version",
"@io_opentelemetry_go_otel//:otel",
"@io_opentelemetry_go_otel//attribute",
"@io_opentelemetry_go_otel//propagation",
Expand Down
140 changes: 140 additions & 0 deletions src/invocation-plane-services/llm-api-gateway/api/info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

echo "github.com/labstack/echo/v4"

golibversion "github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version"
"github.com/NVIDIA/nvcf/src/invocation-plane-services/llm-gateway/config"
)

func newInfoEngine() *echo.Echo {
e := echo.New()
RegisterRoutes(e, NewHandlers(config.Default(), nil, nil))
return e
}

func TestInfoEndpoint_GET(t *testing.T) {
golibversion.Service = "nvcf-llm-api-gateway"
golibversion.Version = "test-1.0.0"
golibversion.GitHash = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
t.Cleanup(func() {
golibversion.Service = ""
golibversion.Version = ""
golibversion.GitHash = ""
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.

e := newInfoEngine()

rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/info", nil)
e.ServeHTTP(rec, req)

if rec.Code != http.StatusOK {
t.Fatalf("GET /info: got status %d, want %d", rec.Code, http.StatusOK)
}
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
t.Errorf("GET /info: got Content-Type %q, want application/json", ct)
}

var info map[string]string
if err := json.Unmarshal(rec.Body.Bytes(), &info); err != nil {
t.Fatalf("GET /info: unmarshal body: %v", err)
}
if info["service"] != "nvcf-llm-api-gateway" {
t.Errorf("GET /info: service = %q, want nvcf-llm-api-gateway", info["service"])
}
if info["version"] != "test-1.0.0" {
t.Errorf("GET /info: version = %q, want test-1.0.0", info["version"])
}
if info["commit"] != "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" {
t.Errorf("GET /info: commit = %q, want aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", info["commit"])
}
}

func TestInfoEndpoint_GET_UnstampedFallback(t *testing.T) {
previousService := golibversion.Service
previousVersion := golibversion.Version
previousGitHash := golibversion.GitHash
golibversion.Service = ""
golibversion.Version = ""
golibversion.GitHash = ""
t.Cleanup(func() {
golibversion.Service = previousService
golibversion.Version = previousVersion
golibversion.GitHash = previousGitHash
})

e := newInfoEngine()

rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/info", nil)
e.ServeHTTP(rec, req)

if rec.Code != http.StatusOK {
t.Fatalf("GET /info: got status %d, want %d", rec.Code, http.StatusOK)
}

var info map[string]string
if err := json.Unmarshal(rec.Body.Bytes(), &info); err != nil {
t.Fatalf("GET /info: unmarshal body: %v", err)
}
if got, want := info["service"], "unknown"; got != want {
t.Errorf("GET /info: service = %q, want %q", got, want)
}
if got, want := info["version"], "unknown"; got != want {
t.Errorf("GET /info: version = %q, want %q", got, want)
}
if info["commit"] == "" {
t.Error("GET /info: commit must be populated")
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

func TestInfoEndpoint_RejectsNonGET(t *testing.T) {
e := newInfoEngine()

for _, method := range []string{
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodOptions,
http.MethodConnect,
http.MethodTrace,
} {
t.Run(method, func(t *testing.T) {
rec := httptest.NewRecorder()
req := httptest.NewRequest(method, "/info", nil)
e.ServeHTTP(rec, req)

if rec.Code != http.StatusMethodNotAllowed {
t.Errorf("%s /info: got status %d, want %d", method, rec.Code, http.StatusMethodNotAllowed)
}
if allow := rec.Header().Get("Allow"); allow != http.MethodGet {
t.Errorf("%s /info: got Allow %q, want %q", method, allow, http.MethodGet)
}
})
}
}
16 changes: 16 additions & 0 deletions src/invocation-plane-services/llm-api-gateway/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"net/http"

echo "github.com/labstack/echo/v4"

golibversion "github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version"
)

func RegisterRoutes(e *echo.Echo, handlers *Handlers) {
Expand All @@ -30,6 +32,20 @@ func RegisterRoutes(e *echo.Echo, handlers *Handlers) {
e.GET("/readyz", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
e.GET("/info", echo.WrapHandler(golibversion.Handler()))
e.Match([]string{
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodOptions,
http.MethodConnect,
http.MethodTrace,
}, "/info", func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderAllow, http.MethodGet)
return c.NoContent(http.StatusMethodNotAllowed)
})

group := e.Group("", rejectClientSuppliedPriority)
handlers.AsOpenAIChatHandlers().RegisterRoutes(group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ go_binary(
name = "llm-api-gateway",
embed = [":llm-api-gateway_lib"],
visibility = ["//visibility:public"],
x_defs = {
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.Service": "nvcf-llm-api-gateway",
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.Version": "{STABLE_VERSION}",
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.GitHash": "{STABLE_GIT_COMMIT_FULL}",
},
)
50 changes: 25 additions & 25 deletions src/invocation-plane-services/llm-api-gateway/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.25.6

require (
cloud.google.com/go/pubsub/v2 v2.4.0
github.com/NVIDIA/nvcf/src/libraries/go/lib v0.0.0-20260513170923-714a7c905aa0
github.com/NVIDIA/nvcf/src/libraries/go/lib v0.0.0-20260728185909-afca4ec2fb26
github.com/go-viper/mapstructure/v2 v2.5.0
github.com/google/uuid v1.6.0
github.com/kaptinlin/jsonrepair v0.2.6
Expand All @@ -21,20 +21,20 @@ require (
go.jetify.com/typeid v1.3.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.62.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0
go.opentelemetry.io/otel v1.42.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.42.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.42.0
go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0
go.opentelemetry.io/otel/exporters/prometheus v0.64.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.42.0
go.opentelemetry.io/otel/metric v1.42.0
go.opentelemetry.io/otel/sdk v1.42.0
go.opentelemetry.io/otel/sdk/metric v1.42.0
go.opentelemetry.io/otel/trace v1.42.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.44.0
go.opentelemetry.io/otel/metric v1.44.0
go.opentelemetry.io/otel/sdk v1.44.0
go.opentelemetry.io/otel/sdk/metric v1.44.0
go.opentelemetry.io/otel/trace v1.44.0
Comment thread
coderabbitai[bot] marked this conversation as resolved.
go.uber.org/mock v0.5.2
golang.org/x/sync v0.20.0
google.golang.org/api v0.272.0
google.golang.org/grpc v1.79.2
google.golang.org/grpc v1.81.1
google.golang.org/protobuf v1.36.11
gotest.tools/v3 v3.5.2
k8s.io/api v0.34.2
Expand Down Expand Up @@ -75,7 +75,7 @@ require (
github.com/google/s2a-go v0.1.9 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect
github.com/googleapis/gax-go/v2 v2.18.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.4 // indirect
Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
github.com/redis/go-redis/v9 v9.8.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
Expand All @@ -120,25 +120,25 @@ require (
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.65.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/crypto v0.51.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/term v0.41.0 // indirect
golang.org/x/text v0.35.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/term v0.43.0 // indirect
golang.org/x/text v0.37.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.42.0 // indirect
golang.org/x/tools v0.44.0 // indirect
google.golang.org/genproto v0.0.0-20260217215200-42d3e9bedb6d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260217215200-42d3e9bedb6d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260311181403-84a4fc48630c // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading
Loading