Skip to content

Commit

Permalink
Add additional logging statement + handle maximum pageSize for listNo…
Browse files Browse the repository at this point in the history
…deVersions endpoint (#116)

Co-authored-by: James Kwon <[email protected]>
  • Loading branch information
james03160927 and james03160927 authored Jan 4, 2025
1 parent 43947e4 commit 2a4d620
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
15 changes: 12 additions & 3 deletions drip/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ paths:
format: int64
description: The end time of the job as a Unix timestamp.
avg_vram:
type: integer
type: integer
description: The average amount of VRAM used in the run.
peak_vram:
type: integer
type: integer
description: The peak amount of VRAM used in the run.
pr_number:
type: string
Expand Down Expand Up @@ -1639,7 +1639,12 @@ paths:
totalPages:
type: integer
description: Total number of pages available

'400':
description: Invalid input, object invalid
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Node banned
content:
Expand Down Expand Up @@ -1677,7 +1682,7 @@ paths:
required: true
content:
application/json:
schema:
schema:
type: object
properties:
status:
Expand Down Expand Up @@ -1760,7 +1765,7 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'
/nodes/{nodeId}/versions/{version}/comfy-nodes:
post:
post:
summary: create comfy-nodes for certain node
operationId: CreateComfyNodes
tags:
Expand All @@ -1780,7 +1785,7 @@ paths:
required: true
content:
application/json:
schema:
schema:
type: object
properties:
nodes:
Expand Down Expand Up @@ -1899,7 +1904,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
PersonalAccessToken:
Expand Down Expand Up @@ -2059,7 +2064,7 @@ components:
git_repo:
type: string
description: The repository name
pr_number:
pr_number:
type: string
description: The pull request number
start_time:
Expand All @@ -2079,12 +2084,12 @@ components:
job_trigger_user:
type: string
description: The user who triggered the job.
author:
author:
type: string
description: The author of the commit
machine_stats:
$ref: "#/components/schemas/MachineStats"
status:
status:
$ref: "#/components/schemas/WorkflowRunStatus"
storage_file:
$ref: "#/components/schemas/StorageFile"
Expand Down Expand Up @@ -2224,7 +2229,7 @@ components:
type: string
description: The reason for the status change.
comfy_nodes:
type: object
type: object
additionalProperties:
$ref: "#/components/schemas/ComfyNode"
node_id:
Expand Down
34 changes: 29 additions & 5 deletions server/implementation/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package implementation
import (
"context"
"errors"
"fmt"
"registry-backend/drip"
"registry-backend/ent"
"registry-backend/ent/publisher"
Expand Down Expand Up @@ -954,16 +955,29 @@ func (s *DripStrictServerImplementation) SecurityScan(

func (s *DripStrictServerImplementation) ListAllNodeVersions(
ctx context.Context, request drip.ListAllNodeVersionsRequestObject) (drip.ListAllNodeVersionsResponseObject, error) {
log.Ctx(ctx).Info().Msg("ListAllNodeVersions request received")
log.Ctx(ctx).Info().Msgf("ListAllNodeVersions request received %+v", request.Params)

// Default values for pagination
page := 1
if request.Params.Page != nil {
page = *request.Params.Page
}

pageSize := 10
if request.Params.PageSize != nil && *request.Params.PageSize < 100 {
maxPageSize := 100
if request.Params.PageSize != nil {
// Validate pageSize
if *request.Params.PageSize > maxPageSize {
log.Ctx(ctx).Error().Msgf(
"Requested pageSize %d exceeds maximum allowed %d", *request.Params.PageSize, maxPageSize)
return drip.ListAllNodeVersions400JSONResponse{
Message: fmt.Sprintf(
"Invalid pageSize: %d. The maximum allowed is %d.", *request.Params.PageSize, maxPageSize),
}, nil
}
pageSize = *request.Params.PageSize
}

f := &drip_services.NodeVersionFilter{
Page: page,
PageSize: pageSize,
Expand All @@ -974,15 +988,22 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions(
f.Status = mapper.ApiNodeVersionStatusesToDbNodeVersionStatuses(request.Params.Statuses)
}

// Log the constructed filter
log.Ctx(ctx).Info().Msgf("Constructed Filter: %+v", f)

// List nodes from the registry service
nodeVersionResults, err := s.RegistryService.ListNodeVersions(ctx, s.Client, f)
if err != nil {
log.Ctx(ctx).Error().Msgf("Failed to list node versions w/ err: %v", err)
return drip.ListAllNodeVersions500JSONResponse{Message: "Failed to list node versions", Error: err.Error()}, nil
return drip.ListAllNodeVersions500JSONResponse{
Message: "Failed to list node versions",
Error: err.Error(),
}, nil
}

// Handle no results
if len(nodeVersionResults.NodeVersions) == 0 {
log.Ctx(ctx).Info().Msg("No node versions found")
log.Ctx(ctx).Info().Msgf("No node versions found. Total: %d", nodeVersionResults.Total)
return drip.ListAllNodeVersions200JSONResponse{
Versions: &[]drip.NodeVersion{},
Total: &nodeVersionResults.Total,
Expand All @@ -992,12 +1013,15 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions(
}, nil
}

// Transform DB results into API results
apiNodeVersions := make([]drip.NodeVersion, 0, len(nodeVersionResults.NodeVersions))
for _, dbNodeVersion := range nodeVersionResults.NodeVersions {
apiNodeVersions = append(apiNodeVersions, *mapper.DbNodeVersionToApiNodeVersion(dbNodeVersion))
}

log.Ctx(ctx).Info().Msgf("Found %d node versions", nodeVersionResults.Total)
// Log success
log.Ctx(ctx).Info().Msgf(
"Found %d node versions. Total: %d", len(nodeVersionResults.NodeVersions), nodeVersionResults.Total)
return drip.ListAllNodeVersions200JSONResponse{
Versions: &apiNodeVersions,
Total: &nodeVersionResults.Total,
Expand Down

0 comments on commit 2a4d620

Please sign in to comment.