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
8 changes: 4 additions & 4 deletions internal/scheduling/reservations/commitments/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (api *HTTPAPI) Init(mux *http.ServeMux, registry prometheus.Registerer, log
registry.MustRegister(&api.usageMonitor)
registry.MustRegister(&api.capacityMonitor)
registry.MustRegister(&api.infoMonitor)
mux.HandleFunc("/v1/commitments/change-commitments", api.HandleChangeCommitments)
mux.HandleFunc("/v1/commitments/report-capacity", api.HandleReportCapacity)
mux.HandleFunc("/v1/commitments/info", api.HandleInfo)
mux.HandleFunc("/v1/commitments/projects/", api.HandleReportUsage) // matches /v1/commitments/projects/:project_id/report-usage
mux.HandleFunc("/commitments/v1/change-commitments", api.HandleChangeCommitments)
mux.HandleFunc("/commitments/v1/report-capacity", api.HandleReportCapacity)
mux.HandleFunc("/commitments/v1/info", api.HandleInfo)
mux.HandleFunc("/commitments/v1/projects/", api.HandleReportUsage) // matches /commitments/v1/projects/:project_id/report-usage

log.Info("commitments API initialized",
"changeCommitmentsEnabled", api.config.EnableChangeCommitmentsAPI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ func (env *CommitmentTestEnv) CallChangeCommitmentsAPI(reqJSON string) (resp liq
}()

// Make HTTP request
url := env.HTTPServer.URL + "/v1/commitments/change-commitments"
url := env.HTTPServer.URL + "/commitments/v1/change-commitments"
httpResp, err := http.Post(url, "application/json", bytes.NewReader([]byte(reqJSON))) //nolint:gosec,noctx // test server URL, not user input
if err != nil {
cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/sapcc/go-api-declarations/liquid"
)

// handles POST /v1/commitments/report-capacity requests from Limes:
// handles POST /commitments/v1/report-capacity requests from Limes:
// See: https://github.com/sapcc/go-api-declarations/blob/main/liquid/commitment.go
// See: https://pkg.go.dev/github.com/sapcc/go-api-declarations/liquid
// Reports available capacity across all flavor group resources. Note, unit is specified in the Info API response with multiple of the smallest memory resource unit within a flavor group.
Expand All @@ -38,7 +38,7 @@ func (api *HTTPAPI) HandleReportCapacity(w http.ResponseWriter, r *http.Request)
}

ctx := reservations.WithGlobalRequestID(r.Context(), "committed-resource-"+requestID)
logger := LoggerFromContext(ctx).WithValues("component", "api", "endpoint", "/v1/commitments/report-capacity")
logger := LoggerFromContext(ctx).WithValues("component", "api", "endpoint", "/commitments/v1/report-capacity")

// Only accept POST method
if r.Method != http.MethodPost {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/sapcc/go-api-declarations/liquid"
)

// HandleReportUsage implements POST /v1/commitments/projects/:project_id/report-usage from Limes LIQUID API.
// HandleReportUsage implements POST /commitments/v1/projects/:project_id/report-usage from Limes LIQUID API.
// See: https://github.com/sapcc/go-api-declarations/blob/main/liquid/report_usage.go
// See: https://pkg.go.dev/github.com/sapcc/go-api-declarations/liquid
//
Expand Down Expand Up @@ -51,7 +51,7 @@ func (api *HTTPAPI) HandleReportUsage(w http.ResponseWriter, r *http.Request) {
}

// Extract project UUID from URL path
// URL pattern: /v1/commitments/projects/:project_id/report-usage
// URL pattern: /commitments/v1/projects/:project_id/report-usage
projectID, err := extractProjectIDFromPath(r.URL.Path)
if err != nil {
log.Error(err, "failed to extract project ID from path")
Expand Down Expand Up @@ -99,9 +99,9 @@ func (api *HTTPAPI) recordUsageMetrics(statusCode int, startTime time.Time) {
}

// extractProjectIDFromPath extracts the project UUID from the URL path.
// Expected path format: /v1/commitments/projects/:project_id/report-usage
// Expected path format: /commitments/v1/projects/:project_id/report-usage
func extractProjectIDFromPath(path string) (string, error) {
// Path: /v1/commitments/projects/<uuid>/report-usage
// Path: /commitments/v1/projects/<uuid>/report-usage
parts := strings.Split(strings.Trim(path, "/"), "/")
// Expected: ["v1", "commitments", "projects", "<uuid>", "report-usage"]
if len(parts) < 5 {
Comment on lines +104 to 107
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update the inline “Expected parts” comment to the new segment order.

Line 106 still says ["v1", "commitments", "projects", "<uuid>", "report-usage"], but with the new path it should be ["commitments", "v1", "projects", "<uuid>", "report-usage"]. This is a minor doc mismatch that can mislead future edits.

Suggested comment fix
-	// Expected: ["v1", "commitments", "projects", "<uuid>", "report-usage"]
+	// Expected: ["commitments", "v1", "projects", "<uuid>", "report-usage"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Path: /commitments/v1/projects/<uuid>/report-usage
parts := strings.Split(strings.Trim(path, "/"), "/")
// Expected: ["v1", "commitments", "projects", "<uuid>", "report-usage"]
if len(parts) < 5 {
// Path: /commitments/v1/projects/<uuid>/report-usage
parts := strings.Split(strings.Trim(path, "/"), "/")
// Expected: ["commitments", "v1", "projects", "<uuid>", "report-usage"]
if len(parts) < 5 {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/scheduling/reservations/commitments/api_report_usage.go` around
lines 104 - 107, Update the inline "Expected parts" comment for the path parsing
in api_report_usage.go to reflect the new segment order; change the comment near
the strings.Split usage (the variables `path` and `parts`) that currently reads
["v1", "commitments", "projects", "<uuid>", "report-usage"] to the new order
["commitments", "v1", "projects", "<uuid>", "report-usage"] so the comment
matches the actual path parsing logic in the function handling
/commitments/v1/projects/<uuid>/report-usage.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (env *UsageTestEnv) CallReportUsageAPI(projectID string, allAZs []string, u
}

// Build URL
url := env.HTTPServer.URL + "/v1/commitments/projects/" + projectID + "/report-usage"
url := env.HTTPServer.URL + "/commitments/v1/projects/" + projectID + "/report-usage"

method := http.MethodPost
if useGET {
Expand Down
4 changes: 2 additions & 2 deletions internal/scheduling/reservations/commitments/e2e_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ type E2EChecksConfig struct {
BaseURL string `json:"baseURL"`
}

// CheckCommitmentsInfoEndpoint sends a GET request to the /v1/commitments/info endpoint
// CheckCommitmentsInfoEndpoint sends a GET request to the /commitments/v1/info endpoint
// and verifies that it returns HTTP 200 with a valid ServiceInfo response.
func CheckCommitmentsInfoEndpoint(ctx context.Context, config E2EChecksConfig) {
baseURL := config.BaseURL
if baseURL == "" {
baseURL = defaultCommitmentsAPIURL
}
apiURL := baseURL + "/v1/commitments/info"
apiURL := baseURL + "/commitments/v1/info"
slog.Info("checking commitments info endpoint", "apiURL", apiURL)

httpReq := must.Return(http.NewRequestWithContext(ctx, http.MethodGet, apiURL, http.NoBody))
Expand Down
Loading