Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 Down
90 changes: 90 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,90 @@
/*
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"

"github.com/NVIDIA/nvcf/src/invocation-plane-services/llm-gateway/config"
)

// newInfoEngine builds an echo engine with the service routes registered so the
// /info endpoint can be exercised the same way it is served at runtime.
func newInfoEngine() *echo.Echo {
e := echo.New()
RegisterRoutes(e, NewHandlers(config.Default(), nil, nil))
return e
}

func TestInfoEndpoint_GET(t *testing.T) {
t.Parallel()

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)
}

// x_defs are not injected under `go test`; resolve() falls back to "unknown"
// for any empty field, so all three values are guaranteed non-empty.
var info map[string]string
if err := json.Unmarshal(rec.Body.Bytes(), &info); err != nil {
t.Fatalf("GET /info: unmarshal body: %v", err)
}
for _, field := range []string{"service", "version", "commit"} {
if info[field] == "" {
t.Errorf("GET /info: field %q must be populated", field)
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

func TestInfoEndpoint_RejectsNonGET(t *testing.T) {
t.Parallel()

e := newInfoEngine()

for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodDelete} {
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)
}
if body := rec.Body.String(); body != "" {
t.Errorf("%s /info: got non-empty body %q", method, body)
}
})
}
}
3 changes: 3 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,7 @@ func RegisterRoutes(e *echo.Echo, handlers *Handlers) {
e.GET("/readyz", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
e.Any("/info", echo.WrapHandler(golibversion.Handler()))
Comment thread
along-2017 marked this conversation as resolved.
Resolved

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}",
},
)
32 changes: 16 additions & 16 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 v1.44.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/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/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.
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.79.3
google.golang.org/protobuf v1.36.11
gotest.tools/v3 v3.5.2
k8s.io/api v0.34.2
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 @@ -125,17 +125,17 @@ require (
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
Expand Down
Loading