Skip to content

Commit

Permalink
fixes influxdata#285, track dates for easy deletion of unused tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed May 5, 2016
1 parent 93e2637 commit fcb60cb
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ For example, let's say we want to store all data that triggered an alert in Infl
- [#491](https://github.com/influxdata/kapacitor/pull/491): BREAKING: Rewriting stateful expression in order to improve performance, the only breaking change is: short circuit evaluation for booleans - for example: ``lambda: "bool_value" && (count() > 100)`` if "bool_value" is false, we won't evaluate "count".
- [#504](https://github.com/influxdata/kapacitor/pull/504): BREAKING: Many changes to the API and underlying storage system. This release requires a special upgrade process.
- [#511](https://github.com/influxdata/kapacitor/pull/511): Adds DefaultNode for providing default values for missing fields or tags.
- [#285](https://github.com/influxdata/kapacitor/pull/285): Track created,modified and last enabled dates on tasks.

### Bugfixes

Expand Down
23 changes: 17 additions & 6 deletions client/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Response with task id and link.
"status" : "enabled",
"executing" : true,
"error" : "",
"created": "2006-01-02T15:04:05Z07:00",
"modified": "2006-01-02T15:04:05Z07:00",
"stats" : {}
}
```
Expand Down Expand Up @@ -204,12 +206,15 @@ To get information about a task make a GET request to the `/kapacitor/v1/tasks/T

A task has these read only properties in addition to the properties listed [above](#define-task).

| Property | Description |
| -------- | ----------- |
| dot | [GraphViz DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) syntax formatted representation of the task DAG. |
| executing | Whether the task is currently executing. |
| error | Any error encountered when executing the task. |
| stats | Map of statistics about a task. |
| Property | Description |
| -------- | ----------- |
| dot | [GraphViz DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) syntax formatted representation of the task DAG. |
| executing | Whether the task is currently executing. |
| error | Any error encountered when executing the task. |
| stats | Map of statistics about a task. |
| created | Date the task was first created |
| modified | Date the task was last modified |
| last-enabled | Date the task was last set to status `enabled` |

#### Example

Expand All @@ -230,6 +235,9 @@ GET /kapacitor/v1/tasks/TASK_ID
"status" : "enabled",
"executing" : true,
"error" : "",
"created": "2006-01-02T15:04:05Z07:00",
"modified": "2006-01-02T15:04:05Z07:00",
"last-enabled": "2006-01-03T15:04:05Z07:00",
"stats" : {}
}
```
Expand All @@ -251,6 +259,9 @@ GET /kapacitor/v1/tasks/TASK_ID?dot-view=labels&script-format=raw
"status" : "enabled",
"executing" : true,
"error" : "",
"created": "2006-01-02T15:04:05Z07:00",
"modified": "2006-01-02T15:04:05Z07:00",
"last-enabled": "2006-01-03T15:04:05Z07:00",
"stats" : {}
}
```
Expand Down
3 changes: 3 additions & 0 deletions client/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ type Task struct {
Executing bool `json:"executing"`
Error string `json:"error"`
ExecutionStats ExecutionStats `json:"stats"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
LastEnabled time.Time `json:"last-enabled,omitempty"`
}

// Information about a recording.
Expand Down
15 changes: 15 additions & 0 deletions client/v1/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,21 @@ definitions:
error:
description: Any error the task may have encountered while executing
readOnly: true
created:
type: string
format: dateTime
description: Date task was first created
readOnly: true
modified:
type: string
format: dateTime
description: Date task was last modified
readOnly: true
last-enabled:
type: string
format: dateTime
description: Date task was last enabled
readOnly: true
stats:
type: object
description: Statisitcs about the task execution
Expand Down
6 changes: 3 additions & 3 deletions cmd/kapacitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,6 @@ func doDefine(args []string) error {
if err != nil {
return err
}
if task.Error != "" {
return errors.New(task.Error)
}

if !*dnoReload && task.Status == client.Enabled {
err := cli.UpdateTask(l, client.UpdateTaskOptions{Status: client.Disabled})
Expand Down Expand Up @@ -875,6 +872,9 @@ func doShow(args []string) error {
fmt.Println("Type:", ti.Type)
fmt.Println("Status:", ti.Status)
fmt.Println("Executing:", ti.Executing)
fmt.Println("Created:", ti.Created.Format(time.RFC822))
fmt.Println("Modified:", ti.Modified.Format(time.RFC822))
fmt.Println("LastEnabled:", ti.LastEnabled.Format(time.RFC822))
fmt.Println("Databases Retention Policies:", ti.DBRPs)
fmt.Printf("TICKscript:\n%s\n\n", ti.TICKscript)
fmt.Printf("DOT:\n%s\n", ti.Dot)
Expand Down
6 changes: 6 additions & 0 deletions services/replay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func (s *Service) handleListRecordings(w http.ResponseWriter, r *http.Request) {
}
case "progress":
value = recording.Progress
default:
httpd.HttpError(w, fmt.Sprintf("unsupported field %q", field), true, http.StatusBadRequest)
return
}
rs[i][field] = value
}
Expand Down Expand Up @@ -707,6 +710,9 @@ func (s *Service) handleListReplays(w http.ResponseWriter, r *http.Request) {
}
case "progress":
value = replay.Progress
default:
httpd.HttpError(w, fmt.Sprintf("unsupported field %q", field), true, http.StatusBadRequest)
return
}
rs[i][field] = value
}
Expand Down
7 changes: 7 additions & 0 deletions services/task_store/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/gob"
"errors"
"path"
"time"

"github.com/influxdata/kapacitor/services/storage"
)
Expand Down Expand Up @@ -86,6 +87,12 @@ type Task struct {
Error string
// Status of the task
Status Status
// Created Date
Created time.Time
// The time the task was last modified
Modified time.Time
// The time the task was last changed to status Enabled.
LastEnabled time.Time
}

type DBRP struct {
Expand Down
33 changes: 33 additions & 0 deletions services/task_store/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,19 @@ func (ts *Service) migrate() error {
}
}

now := time.Now()
newTask := Task{
ID: task.Name,
Type: typ,
DBRPs: dbrps,
TICKscript: task.TICKscript,
Error: task.Error,
Status: status,
Created: now,
Modified: now,
}
if newTask.Status == Enabled {
newTask.LastEnabled = now
}
// Try and create the task in the new store.
err = ts.tasks.Create(newTask)
Expand Down Expand Up @@ -469,6 +475,9 @@ func (ts *Service) handleTask(w http.ResponseWriter, r *http.Request) {
Executing: executing,
Error: errMsg,
ExecutionStats: stats,
Created: raw.Created,
Modified: raw.Modified,
LastEnabled: raw.LastEnabled,
}

w.Write(httpd.MarshalJSON(info, true))
Expand All @@ -485,6 +494,9 @@ var allFields = []string{
"executing",
"error",
"stats",
"created",
"modified",
"last-enabled",
}

func (ts *Service) taskLink(id string) client.Link {
Expand Down Expand Up @@ -607,6 +619,15 @@ func (ts *Service) handleListTasks(w http.ResponseWriter, r *http.Request) {
case Enabled:
value = client.Enabled
}
case "created":
value = task.Created
case "modified":
value = task.Modified
case "last-enabled":
value = task.LastEnabled
default:
httpd.HttpError(w, fmt.Sprintf("unsupported field %q", field), true, http.StatusBadRequest)
return
}
tasks[i][field] = value
}
Expand Down Expand Up @@ -697,6 +718,13 @@ func (ts *Service) handleCreateTask(w http.ResponseWriter, r *http.Request) {
return
}

now := time.Now()
newTask.Created = now
newTask.Modified = now
if newTask.Status == Enabled {
newTask.LastEnabled = now
}

err = ts.tasks.Create(newTask)
if err != nil {
httpd.HttpError(w, err.Error(), true, http.StatusInternalServerError)
Expand Down Expand Up @@ -799,6 +827,11 @@ func (ts *Service) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
return
}

now := time.Now()
existing.Modified = now
if statusChanged && existing.Status == Enabled {
existing.LastEnabled = now
}
err = ts.tasks.Replace(existing)
if err != nil {
httpd.HttpError(w, err.Error(), true, http.StatusInternalServerError)
Expand Down

0 comments on commit fcb60cb

Please sign in to comment.