Skip to content
Open
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
7 changes: 5 additions & 2 deletions manager/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func listPropletsEndpoint(svc manager.Service) endpoint.Endpoint {
return listpropletResponse{}, errors.Join(apiutil.ErrValidation, err)
}

proplets, err := svc.ListProplets(ctx, req.offset, req.limit)
proplets, err := svc.ListProplets(ctx, req.offset, req.limit, req.status)
if err != nil {
return listpropletResponse{}, err
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func listJobsEndpoint(svc manager.Service) endpoint.Endpoint {
return listJobResponse{}, errors.Join(apiutil.ErrValidation, err)
}

jobs, err := svc.ListJobs(ctx, req.offset, req.limit)
jobs, err := svc.ListJobs(ctx, req.offset, req.limit, req.status)
if err != nil {
return listJobResponse{}, err
}
Expand Down Expand Up @@ -231,6 +231,9 @@ func listTasksEndpoint(svc manager.Service) endpoint.Endpoint {
if err := req.validate(); err != nil {
return listTaskResponse{}, errors.Join(apiutil.ErrValidation, err)
}
if req.status != "" {
return listTaskResponse{}, errors.Join(apiutil.ErrValidation, pkgerrors.ErrInvalidValue)
}

tasks, err := svc.ListTasks(ctx, req.offset, req.limit)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions manager/api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (e *entityReq) validate() error {

type listEntityReq struct {
offset, limit uint64
status string
}

func (e *listEntityReq) validate() error {
Expand Down
1 change: 1 addition & 0 deletions manager/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func decodeListEntityReq(_ context.Context, r *http.Request) (any, error) {
return listEntityReq{
offset: o,
limit: l,
status: r.URL.Query().Get("status"),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Service interface {
GetProplet(ctx context.Context, propletID string) (proplet.Proplet, error)
ListProplets(ctx context.Context, offset, limit uint64) (proplet.PropletPage, error)
ListProplets(ctx context.Context, offset, limit uint64, status string) (proplet.PropletPage, error)
SelectProplet(ctx context.Context, task task.Task) (proplet.Proplet, error)
DeleteProplet(ctx context.Context, propletID string) error

Expand All @@ -18,7 +18,7 @@ type Service interface {
CreateJob(ctx context.Context, name string, tasks []task.Task, executionMode string) (string, []task.Task, error)
GetTask(ctx context.Context, taskID string) (task.Task, error)
GetJob(ctx context.Context, jobID string) ([]task.Task, error)
ListJobs(ctx context.Context, offset, limit uint64) (JobPage, error)
ListJobs(ctx context.Context, offset, limit uint64, status string) (JobPage, error)
StartJob(ctx context.Context, jobID string) error
StopJob(ctx context.Context, jobID string) error
ListTasks(ctx context.Context, offset, limit uint64) (task.TaskPage, error)
Expand Down
10 changes: 6 additions & 4 deletions manager/middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ func (lm *loggingMiddleware) GetProplet(ctx context.Context, id string) (resp pr
return lm.svc.GetProplet(ctx, id)
}

func (lm *loggingMiddleware) ListProplets(ctx context.Context, offset, limit uint64) (resp proplet.PropletPage, err error) {
func (lm *loggingMiddleware) ListProplets(ctx context.Context, offset, limit uint64, status string) (resp proplet.PropletPage, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
slog.Uint64("offset", offset),
slog.Uint64("limit", limit),
slog.String("status", status),
}
if err != nil {
args = append(args, slog.Any("error", err))
Expand All @@ -58,7 +59,7 @@ func (lm *loggingMiddleware) ListProplets(ctx context.Context, offset, limit uin
lm.logger.Info("List proplets completed successfully", args...)
}(time.Now())

return lm.svc.ListProplets(ctx, offset, limit)
return lm.svc.ListProplets(ctx, offset, limit, status)
}

func (lm *loggingMiddleware) SelectProplet(ctx context.Context, t task.Task) (w proplet.Proplet, err error) {
Expand Down Expand Up @@ -348,12 +349,13 @@ func (lm *loggingMiddleware) GetJob(ctx context.Context, jobID string) (resp []t
return lm.svc.GetJob(ctx, jobID)
}

func (lm *loggingMiddleware) ListJobs(ctx context.Context, offset, limit uint64) (resp manager.JobPage, err error) {
func (lm *loggingMiddleware) ListJobs(ctx context.Context, offset, limit uint64, status string) (resp manager.JobPage, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
slog.Uint64("offset", offset),
slog.Uint64("limit", limit),
slog.String("status", status),
}
if err != nil {
args = append(args, slog.Any("error", err))
Expand All @@ -365,7 +367,7 @@ func (lm *loggingMiddleware) ListJobs(ctx context.Context, offset, limit uint64)
lm.logger.Info("List jobs completed successfully", args...)
}(time.Now())

return lm.svc.ListJobs(ctx, offset, limit)
return lm.svc.ListJobs(ctx, offset, limit, status)
}

func (lm *loggingMiddleware) StartJob(ctx context.Context, jobID string) (err error) {
Expand Down
8 changes: 4 additions & 4 deletions manager/middleware/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func (mm *metricsMiddleware) GetProplet(ctx context.Context, id string) (proplet
return mm.svc.GetProplet(ctx, id)
}

func (mm *metricsMiddleware) ListProplets(ctx context.Context, offset, limit uint64) (proplet.PropletPage, error) {
func (mm *metricsMiddleware) ListProplets(ctx context.Context, offset, limit uint64, status string) (proplet.PropletPage, error) {
defer func(begin time.Time) {
mm.counter.With("method", "list-proplets").Add(1)
mm.latency.With("method", "list-proplets").Observe(time.Since(begin).Seconds())
}(time.Now())

return mm.svc.ListProplets(ctx, offset, limit)
return mm.svc.ListProplets(ctx, offset, limit, status)
}

func (mm *metricsMiddleware) SelectProplet(ctx context.Context, t task.Task) (proplet.Proplet, error) {
Expand Down Expand Up @@ -170,13 +170,13 @@ func (mm *metricsMiddleware) GetJob(ctx context.Context, jobID string) ([]task.T
return mm.svc.GetJob(ctx, jobID)
}

func (mm *metricsMiddleware) ListJobs(ctx context.Context, offset, limit uint64) (manager.JobPage, error) {
func (mm *metricsMiddleware) ListJobs(ctx context.Context, offset, limit uint64, status string) (manager.JobPage, error) {
defer func(begin time.Time) {
mm.counter.With("method", "list-jobs").Add(1)
mm.latency.With("method", "list-jobs").Observe(time.Since(begin).Seconds())
}(time.Now())

return mm.svc.ListJobs(ctx, offset, limit)
return mm.svc.ListJobs(ctx, offset, limit, status)
}

func (mm *metricsMiddleware) StartJob(ctx context.Context, jobID string) error {
Expand Down
10 changes: 6 additions & 4 deletions manager/middleware/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ func (tm *tracing) GetProplet(ctx context.Context, id string) (resp proplet.Prop
return tm.svc.GetProplet(ctx, id)
}

func (tm *tracing) ListProplets(ctx context.Context, offset, limit uint64) (resp proplet.PropletPage, err error) {
func (tm *tracing) ListProplets(ctx context.Context, offset, limit uint64, status string) (resp proplet.PropletPage, err error) {
ctx, span := tm.tracer.Start(ctx, "list-proplets", trace.WithAttributes(
attribute.Int64("offset", int64(offset)),
attribute.Int64("limit", int64(limit)),
attribute.String("status", status),
))
defer span.End()

return tm.svc.ListProplets(ctx, offset, limit)
return tm.svc.ListProplets(ctx, offset, limit, status)
}

func (tm *tracing) SelectProplet(ctx context.Context, t task.Task) (resp proplet.Proplet, err error) {
Expand Down Expand Up @@ -178,14 +179,15 @@ func (tm *tracing) GetJob(ctx context.Context, jobID string) (resp []task.Task,
return tm.svc.GetJob(ctx, jobID)
}

func (tm *tracing) ListJobs(ctx context.Context, offset, limit uint64) (resp manager.JobPage, err error) {
func (tm *tracing) ListJobs(ctx context.Context, offset, limit uint64, status string) (resp manager.JobPage, err error) {
ctx, span := tm.tracer.Start(ctx, "list-jobs", trace.WithAttributes(
attribute.Int64("offset", int64(offset)),
attribute.Int64("limit", int64(limit)),
attribute.String("status", status),
))
defer span.End()

return tm.svc.ListJobs(ctx, offset, limit)
return tm.svc.ListJobs(ctx, offset, limit, status)
}

func (tm *tracing) StartJob(ctx context.Context, jobID string) (err error) {
Expand Down
60 changes: 36 additions & 24 deletions manager/mocks/service.go

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

Loading