diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5dc944ae..80e5863400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 1. [14631](https://github.com/influxdata/influxdb/pull/14631): Added Github and Apache templates 1. [14631](https://github.com/influxdata/influxdb/pull/14631): Updated name of Local Metrics template 1. [14631](https://github.com/influxdata/influxdb/pull/14631): Dashboards for all Telegraf config bundles now created +1. [14694](https://github.com/influxdata/influxdb/pull/14694): Add ability to find tasks by name. ### UI Improvements diff --git a/http/swagger.yml b/http/swagger.yml index ffa5f14bc5..b50f82d985 100644 --- a/http/swagger.yml +++ b/http/swagger.yml @@ -4206,6 +4206,11 @@ paths: summary: List tasks. parameters: - $ref: '#/components/parameters/TraceSpan' + - in: query + name: name + description: only returns tasks with the specified name + schema: + type: string - in: query name: after schema: diff --git a/http/task_service.go b/http/task_service.go index 211c299d8c..25869d69fb 100644 --- a/http/task_service.go +++ b/http/task_service.go @@ -362,6 +362,10 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs platform.O req.filter.Type = &ttype } + if name := qp.Get("name"); name != "" { + req.filter.Name = &name + } + return req, nil } diff --git a/kv/task.go b/kv/task.go index a42da910d6..ee78e92504 100644 --- a/kv/task.go +++ b/kv/task.go @@ -203,7 +203,7 @@ func (s *Service) findTasks(ctx context.Context, tx Tx, filter influxdb.TaskFilt if filter.User != nil { return s.findTasksByUser(ctx, tx, filter) } else if org != nil { - return s.findTaskByOrg(ctx, tx, filter) + return s.findTasksByOrg(ctx, tx, filter) } return s.findAllTasks(ctx, tx, filter) @@ -270,11 +270,16 @@ func (s *Service) findTasksByUser(ctx context.Context, tx Tx, filter influxdb.Ta break } } + + if filter.Name != nil { + ts = filterByName(ts, *filter.Name) + } + return ts, len(ts), nil } -// findTaskByOrg is a subset of the find tasks function. Used for cleanliness -func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { +// findTasksByOrg is a subset of the find tasks function. Used for cleanliness +func (s *Service) findTasksByOrg(ctx context.Context, tx Tx, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { var org *influxdb.Organization var err error if filter.OrganizationID != nil { @@ -393,6 +398,11 @@ func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.Task break } } + + if filter.Name != nil { + ts = filterByName(ts, *filter.Name) + } + return ts, len(ts), err } @@ -475,9 +485,26 @@ func (s *Service) findAllTasks(ctx context.Context, tx Tx, filter influxdb.TaskF break } } + + if filter.Name != nil { + ts = filterByName(ts, *filter.Name) + } + return ts, len(ts), err } +func filterByName(ts []*influxdb.Task, taskName string) []*influxdb.Task { + filtered := []*influxdb.Task{} + + for _, task := range ts { + if task.Name == taskName { + filtered = append(filtered, task) + } + } + + return filtered +} + // CreateTask creates a new task. // The owner of the task is inferred from the authorizer associated with ctx. func (s *Service) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { diff --git a/task.go b/task.go index d633f93b1a..ec4cc5c5a9 100644 --- a/task.go +++ b/task.go @@ -382,6 +382,7 @@ func (t *TaskUpdate) UpdateFlux(oldFlux string) error { // TaskFilter represents a set of filters that restrict the returned results type TaskFilter struct { Type *string + Name *string After *ID OrganizationID *ID Organization string