Skip to content

Commit

Permalink
Change SearchMetrics endpoint to a POST (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiovincenzi authored Apr 4, 2024
1 parent 89de705 commit 5bd1d6b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions pkg/api/aim2/api/request/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ type SearchRunsRequest struct {

// MetricTuple represents a metric with key and context.
type MetricTuple struct {
Key string `query:"metric"`
Context string `query:"context"`
Key string `json:"key"`
Context string `json:"context"`
}

// SearchMetricsRequest is a request struct for `GET /runs/search/metric` endpoint.
type SearchMetricsRequest struct {
BaseSearchRequest
Metrics []MetricTuple `query:"m"`
Query string `query:"q"`
Steps int `query:"p"`
XAxis string `query:"x_axis"`
SkipSystem bool `query:"skip_system"`
Metrics []MetricTuple `json:"metrics"`
Query string `json:"query"`
Steps int `json:"steps"`
XAxis string `json:"x_axis"`
SkipSystem bool `json:"skip_system"`
}

// SearchAlignedMetricsRequest is a request struct for `GET /runs/search/metric/align` endpoint.
Expand Down
7 changes: 3 additions & 4 deletions pkg/api/aim2/controller/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (c Controller) SearchRuns(ctx *fiber.Ctx) error {
return nil
}

// SearchMetrics handles `GET /runs/search/metric` endpoint.
// SearchMetrics handles `POST /runs/search/metric` endpoint.
func (c Controller) SearchMetrics(ctx *fiber.Ctx) error {
ns, err := middleware.GetNamespaceFromContext(ctx.Context())
if err != nil {
Expand All @@ -136,10 +136,9 @@ func (c Controller) SearchMetrics(ctx *fiber.Ctx) error {
log.Debugf("searchMetrics namespace: %s", ns.Code)

req := request.SearchMetricsRequest{}
if err = ctx.QueryParser(&req); err != nil {
if err = ctx.BodyParser(&req); err != nil {
return fiber.NewError(fiber.StatusUnprocessableEntity, err.Error())
}

if ctx.Query("report_progress") == "" {
req.ReportProgress = true
}
Expand All @@ -163,7 +162,7 @@ func (c Controller) SearchMetrics(ctx *fiber.Ctx) error {
return nil
}

// SearchAlignedMetrics handles `GET /runs/search/metric/align` endpoint.
// SearchAlignedMetrics handles `POST /runs/search/metric/align` endpoint.
func (c Controller) SearchAlignedMetrics(ctx *fiber.Ctx) error {
ns, err := middleware.GetNamespaceFromContext(ctx.Context())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/aim2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r Router) Init(server fiber.Router) {
runs := mainGroup.Group("/runs")
runs.Get("/active/", r.controller.GetRunsActive)
runs.Get("/search/run/", r.controller.SearchRuns)
runs.Get("/search/metric/", r.controller.SearchMetrics)
runs.Post("/search/metric/", r.controller.SearchMetrics)
runs.Post("/search/metric/align/", r.controller.SearchAlignedMetrics)
runs.Get("/:id/info/", r.controller.GetRunInfo)
runs.Post("/:id/metric/get-batch/", r.controller.GetRunMetrics)
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/golang/aim/metric/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql"
"fmt"
"net/http"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -2016,7 +2017,9 @@ func (s *SearchMetricsTestSuite) Test_Ok() {
s.Run(tt.name, func() {
resp := new(bytes.Buffer)
s.Require().Nil(
s.AIMClient().WithQuery(
s.AIMClient().WithMethod(
http.MethodPost,
).WithRequest(
tt.request,
).WithResponseType(
helpers.ResponseTypeBuffer,
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/golang/aim/namespace/flows/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ func (s *MetricFlowTestSuite) searchMetricsAndCompare(
) {
resp := new(bytes.Buffer)
s.Require().Nil(
s.AIMClient().WithNamespace(
s.AIMClient().WithMethod(
http.MethodPost,
).WithNamespace(
namespace,
).WithQuery(
).WithRequest(
request,
).WithResponseType(
helpers.ResponseTypeBuffer,
Expand Down

0 comments on commit 5bd1d6b

Please sign in to comment.