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
16 changes: 10 additions & 6 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func TestFunctionMethodsUseGeneratedRoutes(t *testing.T) {
var batchFilenames []string
var updateBody map[string]bool
var invokeBody map[string]any
var logSearchBody map[string]any
var schedulerCreateBody map[string]any
var schedulerUpdateBody map[string]any
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -358,13 +359,12 @@ func TestFunctionMethodsUseGeneratedRoutes(t *testing.T) {
"limit": 10,
"total": 1,
})
case r.Method == http.MethodGet && r.URL.Path == "/projects/"+projectIDText+"/functions/"+functionIDText+"/logs":
assert.Equal(t, "50", r.URL.Query().Get("limit"))
assert.Equal(t, "fn-next", r.URL.Query().Get("next_token"))
case r.Method == http.MethodPost && r.URL.Path == "/projects/"+projectIDText+"/logs/search":
require.NoError(t, json.NewDecoder(r.Body).Decode(&logSearchBody))
writeAPIJSON(t, w, http.StatusOK, logsResponse("function runtime"))
case r.Method == http.MethodGet && r.URL.Path == "/projects/"+projectIDText+"/functions/"+functionIDText+"/deployments/"+deploymentIDText+"/logs":
assert.Equal(t, "75", r.URL.Query().Get("limit"))
assert.Equal(t, "dep-next", r.URL.Query().Get("next_token"))
assert.Equal(t, "dep-next", r.URL.Query().Get("cursor"))
writeAPIJSON(t, w, http.StatusOK, logsResponse("deployment build"))
case r.Method == http.MethodGet && r.URL.Path == "/projects/"+projectIDText+"/functions/"+functionIDText+"/schedulers":
writeAPIJSON(t, w, http.StatusOK, map[string]any{
Expand Down Expand Up @@ -463,6 +463,10 @@ func TestFunctionMethodsUseGeneratedRoutes(t *testing.T) {
runtimeLogs, err := client.GetFunctionLogs(context.Background(), projectID, functionID, 50, "fn-next")
require.NoError(t, err)
assert.Equal(t, "function runtime", runtimeLogs.Data[0].Message)
assert.Equal(t, "function", logSearchBody["resource_type"])
assert.Equal(t, []any{functionIDText}, logSearchBody["resource_ids"])
assert.InEpsilon(t, 50, logSearchBody["limit"], 0)
assert.Equal(t, "fn-next", logSearchBody["cursor"])

deploymentLogs, err := client.GetFunctionDeploymentLogs(context.Background(), projectID, functionID, deploymentID, 75, "dep-next")
require.NoError(t, err)
Expand Down Expand Up @@ -513,8 +517,8 @@ func TestFunctionMethodsUseGeneratedRoutes(t *testing.T) {
"POST /functions/" + functionIDText + "/invoke",
"GET /functions/runtimes",
"GET /projects/" + projectIDText + "/functions/" + functionIDText + "/deployments?page=3&limit=10",
"GET /projects/" + projectIDText + "/functions/" + functionIDText + "/logs?limit=50&next_token=fn-next",
"GET /projects/" + projectIDText + "/functions/" + functionIDText + "/deployments/" + deploymentIDText + "/logs?limit=75&next_token=dep-next",
"POST /projects/" + projectIDText + "/logs/search",
"GET /projects/" + projectIDText + "/functions/" + functionIDText + "/deployments/" + deploymentIDText + "/logs?limit=75&cursor=dep-next",
"GET /projects/" + projectIDText + "/functions/" + functionIDText + "/schedulers",
"POST /projects/" + projectIDText + "/functions/" + functionIDText + "/schedulers",
"PATCH /projects/" + projectIDText + "/functions/" + functionIDText + "/schedulers/" + schedulerIDText,
Expand Down
12 changes: 6 additions & 6 deletions internal/api/frontends.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func (c *Client) ListFrontendDeployments(ctx context.Context, projectID, fronten
}

// GetFrontendLogs returns one runtime log page for a frontend.
func (c *Client) GetFrontendLogs(ctx context.Context, projectID, frontendID uuid.UUID, limit int, nextToken string) (*apiclient.GetLogsResponse, error) {
func (c *Client) GetFrontendLogs(ctx context.Context, projectID, frontendID uuid.UUID, limit int, cursor string) (*apiclient.ListLogsResponse, error) {
params := &apiclient.GetFrontendLogsParams{}
if limit > 0 {
params.Limit = &limit
}
if nextToken = strings.TrimSpace(nextToken); nextToken != "" {
params.NextToken = &nextToken
if cursor = strings.TrimSpace(cursor); cursor != "" {
params.Cursor = &cursor
}

resp, err := c.client.GetFrontendLogsWithResponse(ctx, projectID, frontendID, params)
Expand All @@ -135,13 +135,13 @@ func (c *Client) GetFrontendLogs(ctx context.Context, projectID, frontendID uuid
}

// GetFrontendDeploymentLogs returns one build log page for a frontend deployment.
func (c *Client) GetFrontendDeploymentLogs(ctx context.Context, projectID, frontendID, deploymentID uuid.UUID, limit int, nextToken string) (*apiclient.GetLogsResponse, error) {
func (c *Client) GetFrontendDeploymentLogs(ctx context.Context, projectID, frontendID, deploymentID uuid.UUID, limit int, cursor string) (*apiclient.ListLogsResponse, error) {
params := &apiclient.GetFrontendDeploymentLogsParams{}
if limit > 0 {
params.Limit = &limit
}
if nextToken = strings.TrimSpace(nextToken); nextToken != "" {
params.NextToken = &nextToken
if cursor = strings.TrimSpace(cursor); cursor != "" {
params.Cursor = &cursor
}

resp, err := c.client.GetFrontendDeploymentLogsWithResponse(ctx, projectID, frontendID, deploymentID, params)
Expand Down
8 changes: 4 additions & 4 deletions internal/api/frontends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func TestFrontendDomainAndLogsMethodsUseGeneratedRoutes(t *testing.T) {
})
case r.Method == http.MethodGet && r.URL.Path == "/projects/"+projectIDText+"/frontends/"+frontendIDText+"/logs":
assert.Equal(t, "50", r.URL.Query().Get("limit"))
assert.Equal(t, "fe-next", r.URL.Query().Get("next_token"))
assert.Equal(t, "fe-next", r.URL.Query().Get("cursor"))
writeAPIJSON(t, w, http.StatusOK, logsResponse("frontend runtime"))
case r.Method == http.MethodGet && r.URL.Path == "/projects/"+projectIDText+"/frontends/"+frontendIDText+"/deployments/"+deploymentIDText+"/logs":
assert.Equal(t, "75", r.URL.Query().Get("limit"))
assert.Equal(t, "dep-next", r.URL.Query().Get("next_token"))
assert.Equal(t, "dep-next", r.URL.Query().Get("cursor"))
writeAPIJSON(t, w, http.StatusOK, logsResponse("frontend build"))
case r.Method == http.MethodPost && r.URL.Path == "/projects/"+projectIDText+"/frontends/"+frontendIDText+"/domain":
require.NoError(t, json.NewDecoder(r.Body).Decode(&createBody))
Expand Down Expand Up @@ -151,8 +151,8 @@ func TestFrontendDomainAndLogsMethodsUseGeneratedRoutes(t *testing.T) {
require.NoError(t, client.DeleteFrontendCustomDomain(context.Background(), projectID, frontendID))
assert.Equal(t, []string{
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/deployments?page=3&limit=10",
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/logs?limit=50&next_token=fe-next",
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/deployments/" + deploymentIDText + "/logs?limit=75&next_token=dep-next",
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/logs?limit=50&cursor=fe-next",
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/deployments/" + deploymentIDText + "/logs?limit=75&cursor=dep-next",
"POST /projects/" + projectIDText + "/frontends/" + frontendIDText + "/domain",
"GET /projects/" + projectIDText + "/frontends/" + frontendIDText + "/domain",
"DELETE /projects/" + projectIDText + "/frontends/" + frontendIDText + "/domain",
Expand Down
25 changes: 15 additions & 10 deletions internal/api/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/google/uuid"

"github.com/Kong/volcano-cli/internal/apiclient"
apicommon "github.com/Kong/volcano-cli/internal/apiclient/common"
"github.com/Kong/volcano-cli/internal/archive"
)

Expand Down Expand Up @@ -155,17 +156,21 @@ func (c *Client) ListFunctionDeployments(ctx context.Context, projectID, functio
return apiResult(resp.StatusCode(), resp.Body, resp.JSON200, resp.JSON404)
}

// GetFunctionLogs returns one runtime log page for a function.
func (c *Client) GetFunctionLogs(ctx context.Context, projectID, functionID uuid.UUID, limit int, nextToken string) (*apiclient.GetLogsResponse, error) {
params := &apiclient.GetFunctionLogsParams{}
// GetFunctionLogs returns one runtime log search page for a function.
func (c *Client) GetFunctionLogs(ctx context.Context, projectID, functionID uuid.UUID, limit int, cursor string) (*apiclient.LogSearchResponse, error) {
resourceID := functionID.String()
body := apiclient.SearchProjectLogsJSONRequestBody{
ResourceType: apicommon.LogSearchRequestResourceTypeFunction,
ResourceIds: &[]string{resourceID},
}
if limit > 0 {
params.Limit = &limit
body.Limit = &limit
}
if nextToken = strings.TrimSpace(nextToken); nextToken != "" {
params.NextToken = &nextToken
if cursor = strings.TrimSpace(cursor); cursor != "" {
body.Cursor = &cursor
}

resp, err := c.client.GetFunctionLogsWithResponse(ctx, projectID, functionID, params)
resp, err := c.client.SearchProjectLogsWithResponse(ctx, projectID, body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -301,13 +306,13 @@ func (c *Client) DeleteFunctionScheduler(ctx context.Context, projectID, functio
}

// GetFunctionDeploymentLogs returns one build log page for a function deployment.
func (c *Client) GetFunctionDeploymentLogs(ctx context.Context, projectID, functionID, deploymentID uuid.UUID, limit int, nextToken string) (*apiclient.GetLogsResponse, error) {
func (c *Client) GetFunctionDeploymentLogs(ctx context.Context, projectID, functionID, deploymentID uuid.UUID, limit int, cursor string) (*apiclient.ListLogsResponse, error) {
params := &apiclient.GetFunctionDeploymentLogsParams{}
if limit > 0 {
params.Limit = &limit
}
if nextToken = strings.TrimSpace(nextToken); nextToken != "" {
params.NextToken = &nextToken
if cursor = strings.TrimSpace(cursor); cursor != "" {
params.Cursor = &cursor
}

resp, err := c.client.GetFunctionDeploymentLogsWithResponse(ctx, projectID, functionID, deploymentID, params)
Expand Down
Loading
Loading