Skip to content

Commit

Permalink
clean up get status, define URL paths
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Feb 11, 2025
1 parent df5043d commit 53aed88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions client/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
Expand All @@ -12,12 +11,13 @@ import (
)

// GetPackageStatus fetches the GPUd package status from the GPUd admin API.
func GetPackageStatus(ctx context.Context, url string) ([]packages.PackageStatus, error) {
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
func GetPackageStatus(ctx context.Context, url string, opts ...OpOption) ([]packages.PackageStatus, error) {
op := &Op{}
if err := op.applyOpts(opts); err != nil {
return nil, err
}

Check warning on line 18 in client/v1/status.go

View check run for this annotation

Codecov / codecov/patch

client/v1/status.go#L17-L18

Added lines #L17 - L18 were not covered by tests

httpClient := op.httpClient
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion cmd/gpud/command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
client "github.com/leptonai/gpud/client/v1"
"github.com/leptonai/gpud/config"
"github.com/leptonai/gpud/errdefs"
"github.com/leptonai/gpud/internal/server"
"github.com/leptonai/gpud/log"
"github.com/leptonai/gpud/pkg/systemd"
)
Expand Down Expand Up @@ -52,7 +53,7 @@ func cmdStatus(cliContext *cli.Context) error {

for {
cctx, ccancel := context.WithTimeout(rootCtx, 15*time.Second)
packageStatus, err := client.GetPackageStatus(cctx, fmt.Sprintf("https://localhost:%d/admin/packages", config.DefaultGPUdPort))
packageStatus, err := client.GetPackageStatus(cctx, fmt.Sprintf("https://localhost:%d%s", config.DefaultGPUdPort, server.URLPathAdminPackages))
ccancel()

Check warning on line 57 in cmd/gpud/command/status.go

View check run for this annotation

Codecov / codecov/patch

cmd/gpud/command/status.go#L55-L57

Added lines #L55 - L57 were not covered by tests
if err != nil {
fmt.Printf("%s failed to get package status: %v\n", warningSign, err)
Expand Down
10 changes: 8 additions & 2 deletions internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"path"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -149,8 +150,13 @@ func createConfigHandler(cfg *lep_config.Config) func(c *gin.Context) {
}

const (
URLPathPackages = "/packages"
URLPathPackagesDesc = "Get the status of gpud managed packages"
urlPathAdmin = "/admin"
urlPathPackages = "/packages"
urlPathPackagesDesc = "Get the status of gpud managed packages"
)

var (
URLPathAdminPackages = path.Join(urlPathAdmin, urlPathPackages)
)

func createPackageHandler(m *manager.Manager) func(c *gin.Context) {
Expand Down
8 changes: 4 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,17 +1164,17 @@ func New(ctx context.Context, config *lepconfig.Config, endpoint string, cliUID
Desc: URLPathHealthzDesc,
})

admin := router.Group("/admin")
admin := router.Group(urlPathAdmin)

Check warning on line 1167 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L1167

Added line #L1167 was not covered by tests

admin.GET(URLPathConfig, createConfigHandler(config))
registeredPaths = append(registeredPaths, componentHandlerDescription{
Path: path.Join("/admin", URLPathConfig),
Desc: URLPathConfigDesc,
})
admin.GET(URLPathPackages, createPackageHandler(packageManager))
admin.GET(urlPathPackages, createPackageHandler(packageManager))

Check warning on line 1174 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L1174

Added line #L1174 was not covered by tests
registeredPaths = append(registeredPaths, componentHandlerDescription{
Path: path.Join("/admin", URLPathPackages),
Desc: URLPathPackagesDesc,
Path: URLPathAdminPackages,
Desc: urlPathPackagesDesc,

Check warning on line 1177 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L1176-L1177

Added lines #L1176 - L1177 were not covered by tests
})

if config.Pprof {
Expand Down

0 comments on commit 53aed88

Please sign in to comment.