Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Added Last run status and error messages to check, tasks, and notification rules #16325

Closed
wants to merge 13 commits into from
Closed
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
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
### Features

1. [16234](https://github.com/influxdata/influxdb/pull/16234): Add support for notification endpoints to influx templates/pkgs.
2. [16242](https://github.com/influxdata/influxdb/pull/16242): Drop id prefix for secret key requirement for notification endpoints
3. [16259](https://github.com/influxdata/influxdb/pull/16259): Add support for check resource to pkger parser
4. [16262](https://github.com/influxdata/influxdb/pull/16262): Add support for check resource pkger dry run functionality
5. [16275](https://github.com/influxdata/influxdb/pull/16275): Add support for check resource pkger apply functionality
6. [16283](https://github.com/influxdata/influxdb/pull/16283): Add support for check resource pkger export functionality
1. [16242](https://github.com/influxdata/influxdb/pull/16242): Drop id prefix for secret key requirement for notification endpoints
1. [16259](https://github.com/influxdata/influxdb/pull/16259): Add support for check resource to pkger parser
1. [16262](https://github.com/influxdata/influxdb/pull/16262): Add support for check resource pkger dry run functionality
1. [16275](https://github.com/influxdata/influxdb/pull/16275): Add support for check resource pkger apply functionality
1. [16283](https://github.com/influxdata/influxdb/pull/16283): Add support for check resource pkger export functionality
1. [16212](https://github.com/influxdata/influxdb/pull/16212): Add new kv.ForwardCursor interface
1. [16297](https://github.com/influxdata/influxdb/pull/16297): Add support for notification rule to pkger parser
1. [16298](https://github.com/influxdata/influxdb/pull/16298): Add support for notification rule pkger dry run functionality
Expand All @@ -17,6 +17,7 @@
1. [16322](https://github.com/influxdata/influxdb/pull/16322): Add support for tasks to pkger dry run functionality
1. [16323](https://github.com/influxdata/influxdb/pull/16323): Add support for tasks to pkger apply functionality
1. [16324](https://github.com/influxdata/influxdb/pull/16324): Add support for tasks to pkger export functionality
1. [16325](https://github.com/influxdata/influxdb/pull/16325): Add support for last run status, last completed, last run scheduled, and last run error for checks and notification rules

### Bug Fixes

Expand Down
37 changes: 27 additions & 10 deletions http/check_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"

"github.com/influxdata/httprouter"
"github.com/influxdata/influxdb"
Expand Down Expand Up @@ -138,9 +139,13 @@ type checkLinks struct {

type checkResponse struct {
influxdb.Check
Status string `json:"status"`
Labels []influxdb.Label `json:"labels"`
Links checkLinks `json:"links"`
Status string `json:"status"`
Labels []influxdb.Label `json:"labels"`
Links checkLinks `json:"links"`
LatestCompleted time.Time `json:"latestCompleted,omitempty"`
LatestScheduled time.Time `json:"latestScheduled,omitempty"`
LastRunStatus string `json:"LastRunStatus,omitempty"`
LastRunError string `json:"LastRunError,omitempty"`
}

type postCheckRequest struct {
Expand All @@ -159,13 +164,21 @@ func (resp checkResponse) MarshalJSON() ([]byte, error) {
}

b2, err := json.Marshal(struct {
Labels []influxdb.Label `json:"labels"`
Links checkLinks `json:"links"`
Status string `json:"status"`
Labels []influxdb.Label `json:"labels"`
Links checkLinks `json:"links"`
Status string `json:"status"`
LatestCompleted time.Time `json:"latestCompleted,omitempty"`
LatestScheduled time.Time `json:"latestScheduled,omitempty"`
LastRunStatus string `json:"lastRunStatus,omitempty"`
LastRunError string `json:"lastRunError,omitempty"`
}{
Links: resp.Links,
Labels: resp.Labels,
Status: resp.Status,
Links: resp.Links,
Labels: resp.Labels,
Status: resp.Status,
LatestCompleted: resp.LatestCompleted,
LatestScheduled: resp.LatestScheduled,
LastRunStatus: resp.LastRunStatus,
LastRunError: resp.LastRunError,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -198,7 +211,11 @@ func (h *CheckHandler) newCheckResponse(ctx context.Context, chk influxdb.Check,
Owners: fmt.Sprintf("/api/v2/checks/%s/owners", chk.GetID()),
Query: fmt.Sprintf("/api/v2/checks/%s/query", chk.GetID()),
},
Labels: []influxdb.Label{},
Labels: []influxdb.Label{},
LatestCompleted: task.LatestCompleted,
LatestScheduled: task.LatestScheduled,
LastRunStatus: task.LastRunStatus,
LastRunError: task.LastRunError,
}

for _, l := range labels {
Expand Down
24 changes: 18 additions & 6 deletions http/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ func TestService_handleGetChecks(t *testing.T) {
}
}
],
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
},
{
"links": {
Expand Down Expand Up @@ -230,7 +232,9 @@ func TestService_handleGetChecks(t *testing.T) {
}
}
],
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}
]
}
Expand Down Expand Up @@ -520,7 +524,9 @@ func TestService_handleGetCheck(t *testing.T) {
"type": "deadman",
"orgID": "020f755c3c082000",
"name": "hello",
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}
`,
},
Expand Down Expand Up @@ -703,7 +709,9 @@ func TestService_handlePostCheck(t *testing.T) {
"every": "5m",
"level": "WARN",
"labels": [],
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure- but would this not also include LastRunStatus and LastRunError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree in that we need to test out the LastRunStatus and LastRunError. They should be included for tests that result in an error

}
`,
},
Expand Down Expand Up @@ -949,7 +957,9 @@ func TestService_handlePatchCheck(t *testing.T) {
"statusMessageTemplate": "",
"tags": null,
"type": "deadman",
"labels": []
"labels": [],
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}
`,
},
Expand Down Expand Up @@ -1130,7 +1140,9 @@ func TestService_handleUpdateCheck(t *testing.T) {
"statusMessageTemplate": "",
"tags": null,
"type": "deadman",
"labels": []
"labels": [],
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}
`,
},
Expand Down
39 changes: 28 additions & 11 deletions http/notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/influxdata/httprouter"
"github.com/influxdata/influxdb"
Expand Down Expand Up @@ -146,9 +147,13 @@ type notificationRuleLinks struct {

type notificationRuleResponse struct {
influxdb.NotificationRule
Labels []influxdb.Label `json:"labels"`
Links notificationRuleLinks `json:"links"`
Status string `json:"status"`
Labels []influxdb.Label `json:"labels"`
Links notificationRuleLinks `json:"links"`
Status string `json:"status"`
LatestCompleted time.Time `json:"latestCompleted,omitempty"`
LatestScheduled time.Time `json:"latestScheduled,omitempty"`
LastRunStatus string `json:"LastRunStatus,omitempty"`
LastRunError string `json:"LastRunError,omitempty"`
}

func (resp notificationRuleResponse) MarshalJSON() ([]byte, error) {
Expand All @@ -158,13 +163,21 @@ func (resp notificationRuleResponse) MarshalJSON() ([]byte, error) {
}

b2, err := json.Marshal(struct {
Labels []influxdb.Label `json:"labels"`
Links notificationRuleLinks `json:"links"`
Status string `json:"status"`
Labels []influxdb.Label `json:"labels"`
Links notificationRuleLinks `json:"links"`
Status string `json:"status"`
LatestCompleted time.Time `json:"latestCompleted,omitempty"`
LatestScheduled time.Time `json:"latestScheduled,omitempty"`
LastRunStatus string `json:"lastRunStatus,omitempty"`
LastRunError string `json:"lastRunError,omitempty"`
}{
Links: resp.Links,
Labels: resp.Labels,
Status: resp.Status,
Links: resp.Links,
Labels: resp.Labels,
Status: resp.Status,
LatestCompleted: resp.LatestCompleted,
LatestScheduled: resp.LatestScheduled,
LastRunStatus: resp.LastRunStatus,
LastRunError: resp.LastRunError,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -195,8 +208,12 @@ func (h *NotificationRuleHandler) newNotificationRuleResponse(ctx context.Contex
Owners: fmt.Sprintf("/api/v2/notificationRules/%s/owners", nr.GetID()),
Query: fmt.Sprintf("/api/v2/notificationRules/%s/query", nr.GetID()),
},
Labels: []influxdb.Label{},
Status: t.Status,
Labels: []influxdb.Label{},
Status: t.Status,
LatestCompleted: t.LatestCompleted,
LatestScheduled: t.LatestScheduled,
LastRunStatus: t.LastRunStatus,
LastRunError: t.LastRunError,
}

for _, l := range labels {
Expand Down
12 changes: 9 additions & 3 deletions http/notification_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ func Test_newNotificationRuleResponses(t *testing.T) {
],
"type": "slack",
"updatedAt": "0001-01-01T00:00:00Z",
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
},
{
"createdAt": "0001-01-01T00:00:00Z",
Expand All @@ -170,7 +172,9 @@ func Test_newNotificationRuleResponses(t *testing.T) {
"runbookLink": "",
"type": "pagerduty",
"updatedAt": "0001-01-01T00:00:00Z",
"status": "active"
"status": "active",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}
]
}`,
Expand Down Expand Up @@ -287,7 +291,9 @@ func Test_newNotificationRuleResponse(t *testing.T) {
}
],
"type": "slack",
"updatedAt": "0001-01-01T00:00:00Z"
"updatedAt": "0001-01-01T00:00:00Z",
"latestCompleted": "0001-01-01T00:00:00Z",
"latestScheduled": "0001-01-01T00:00:00Z"
}`,
},
}
Expand Down
30 changes: 30 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10214,6 +10214,21 @@ components:
statusMessageTemplate:
description: The template used to generate and write a status message.
type: string
latestCompleted:
description: Timestamp of latest scheduled, completed run, RFC3339.
type: string
format: date-time
readOnly: true
lastRunStatus:
readOnly: true
type: string
enum:
- failed
- success
- canceled
lastRunError:
readOnly: true
type: string
labels:
$ref: "#/components/schemas/Labels"
links:
Expand Down Expand Up @@ -10390,6 +10405,21 @@ components:
- statusRules
- endpointID
properties:
latestCompleted:
description: Timestamp of latest scheduled, completed run, RFC3339.
type: string
format: date-time
readOnly: true
lastRunStatus:
readOnly: true
type: string
enum:
- failed
- success
- canceled
lastRunError:
readOnly: true
type: string
id:
readOnly: true
type: string
Expand Down
2 changes: 1 addition & 1 deletion ui/src/alerting/actions/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {
GetState,
RemoteDataState,
CheckViewProperties,
Label,
PostCheck,
} from 'src/types'
import {Label} from 'src/client'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're for serious about this, it'd be easier to just import the Label definition into 'src/types' instead

import {createView} from 'src/shared/utils/view'

export type Action =
Expand Down
2 changes: 1 addition & 1 deletion ui/src/alerting/actions/notifications/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import * as copy from 'src/shared/copy/notifications'
import {
NotificationEndpoint,
GetState,
Label,
NotificationEndpointUpdate,
PostNotificationEndpoint,
} from 'src/types'
import {Label} from 'src/client'
import {RemoteDataState} from '@influxdata/clockface'

export type Action =
Expand Down
2 changes: 1 addition & 1 deletion ui/src/alerting/actions/notifications/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
NotificationRuleUpdate,
GetState,
NotificationRuleDraft,
Label,
} from 'src/types'
import {Label} from 'src/client'
import {incrementCloneName} from 'src/utils/naming'

export type Action =
Expand Down
15 changes: 11 additions & 4 deletions ui/src/alerting/components/CheckCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {withRouter, WithRouterProps} from 'react-router'
import {SlideToggle, ComponentSize, ResourceCard} from '@influxdata/clockface'
import CheckCardContext from 'src/alerting/components/CheckCardContext'
import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'
import LastRunTaskStatus from 'src/shared/components/lastRunTaskStatus/LastRunTaskStatus'

// Constants
import {DEFAULT_CHECK_NAME} from 'src/alerting/constants'
Expand All @@ -26,8 +27,8 @@ import {notify} from 'src/shared/actions/notifications'
import {updateCheckFailed} from 'src/shared/copy/notifications'

// Types
import {Check, Label, AppState} from 'src/types'

import {Check, AppState} from 'src/types'
import {Label, Labels} from 'src/client'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels are going to be such a mess as we switch from @influxdata/influx to oats!

// Utilities
import {relativeTimestampFormatter} from 'src/shared/utils/relativeTimestampFormatter'

Expand All @@ -42,7 +43,7 @@ interface DispatchProps {
}

interface StateProps {
labels: Label[]
labels: Labels
}

interface OwnProps {
Expand Down Expand Up @@ -154,7 +155,7 @@ const CheckCard: FunctionComponent<Props> = ({
}
labels={
<InlineLabels
selectedLabels={check.labels as Label[]}
selectedLabels={check.labels}
labels={labels}
onAddLabel={handleAddCheckLabel}
onRemoveLabel={handleRemoveCheckLabel}
Expand All @@ -170,7 +171,13 @@ const CheckCard: FunctionComponent<Props> = ({
/>
}
metaData={[
<>Last completed at {check.latestCompleted}</>,
<>{relativeTimestampFormatter(check.updatedAt, 'Last updated ')}</>,
<LastRunTaskStatus
key={2}
asalem1 marked this conversation as resolved.
Show resolved Hide resolved
lastRunError={check.lastRunError}
lastRunStatus={check.lastRunStatus}
/>,
]}
/>
)
Expand Down
Loading