Skip to content

Commit b70d822

Browse files
authored
Filter alerts - Add ThrottleTimeSeconds and ThrottleField (#166)
1 parent 517aa79 commit b70d822

4 files changed

Lines changed: 83 additions & 65 deletions

File tree

api/filter-alerts.go

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import (
77
)
88

99
type FilterAlert struct {
10-
ID string `graphql:"id" yaml:"-" json:"id"`
11-
Name string `graphql:"name" yaml:"name" json:"name"`
12-
Description string `graphql:"description" yaml:"description,omitempty" json:"description,omitempty"`
13-
QueryString string `graphql:"queryString" yaml:"queryString" json:"queryString"`
14-
ActionNames []string `graphql:"actionNames" yaml:"actionNames" json:"actionNames"`
15-
Labels []string `graphql:"labels" yaml:"labels" json:"labels"`
16-
Enabled bool `graphql:"enabled" yaml:"enabled" json:"enabled"`
17-
QueryOwnershipType string `graphql:"queryOwnership" yaml:"queryOwnershipType" json:"queryOwnershipType"`
18-
RunAsUserID string `graphql:"runAsUserId" yaml:"runAsUserId,omitempty" json:"runAsUserId,omitempty"`
10+
ID string `graphql:"id" yaml:"-" json:"id"`
11+
Name string `graphql:"name" yaml:"name" json:"name"`
12+
Description string `graphql:"description" yaml:"description,omitempty" json:"description,omitempty"`
13+
QueryString string `graphql:"queryString" yaml:"queryString" json:"queryString"`
14+
ActionNames []string `graphql:"actionNames" yaml:"actionNames" json:"actionNames"`
15+
Labels []string `graphql:"labels" yaml:"labels" json:"labels"`
16+
Enabled bool `graphql:"enabled" yaml:"enabled" json:"enabled"`
17+
QueryOwnershipType string `graphql:"queryOwnership" yaml:"queryOwnershipType" json:"queryOwnershipType"`
18+
ThrottleTimeSeconds int `graphql:"throttleTimeSeconds" yaml:"throttleTimeSeconds,omitempty" json:"throttleTimeSeconds,omitempty"`
19+
ThrottleField string `graphql:"throttleField" yaml:"throttleField,omitempty" json:"throttleField"`
20+
RunAsUserID string `graphql:"runAsUserId" yaml:"runAsUserId,omitempty" json:"runAsUserId,omitempty"`
1921
}
2022

2123
type FilterAlerts struct {
@@ -72,16 +74,18 @@ func (fa *FilterAlerts) Update(viewName string, updatedFilterAlert *FilterAlert)
7274
}
7375

7476
updateAlert := humiographql.UpdateFilterAlert{
75-
ViewName: humiographql.RepoOrViewName(viewName),
76-
ID: graphql.String(updatedFilterAlert.ID),
77-
Name: graphql.String(updatedFilterAlert.Name),
78-
Description: graphql.String(updatedFilterAlert.Description),
79-
QueryString: graphql.String(updatedFilterAlert.QueryString),
80-
ActionIdsOrNames: actionNames,
81-
Labels: labels,
82-
Enabled: graphql.Boolean(updatedFilterAlert.Enabled),
83-
RunAsUserID: graphql.String(updatedFilterAlert.RunAsUserID),
84-
QueryOwnershipType: humiographql.QueryOwnershipType(updatedFilterAlert.QueryOwnershipType),
77+
ViewName: humiographql.RepoOrViewName(viewName),
78+
ID: graphql.String(updatedFilterAlert.ID),
79+
Name: graphql.String(updatedFilterAlert.Name),
80+
Description: graphql.String(updatedFilterAlert.Description),
81+
QueryString: graphql.String(updatedFilterAlert.QueryString),
82+
ActionIdsOrNames: actionNames,
83+
Labels: labels,
84+
Enabled: graphql.Boolean(updatedFilterAlert.Enabled),
85+
RunAsUserID: graphql.String(updatedFilterAlert.RunAsUserID),
86+
ThrottleTimeSeconds: humiographql.Long(updatedFilterAlert.ThrottleTimeSeconds),
87+
ThrottleField: graphql.String(updatedFilterAlert.ThrottleField),
88+
QueryOwnershipType: humiographql.QueryOwnershipType(updatedFilterAlert.QueryOwnershipType),
8589
}
8690

8791
variables := map[string]any{
@@ -118,15 +122,17 @@ func (fa *FilterAlerts) Create(viewName string, newFilterAlert *FilterAlert) (*F
118122
}
119123

120124
createFilterAlert := humiographql.CreateFilterAlert{
121-
ViewName: humiographql.RepoOrViewName(viewName),
122-
Name: graphql.String(newFilterAlert.Name),
123-
Description: graphql.String(newFilterAlert.Description),
124-
QueryString: graphql.String(newFilterAlert.QueryString),
125-
ActionIdsOrNames: actionNames,
126-
Labels: labels,
127-
Enabled: graphql.Boolean(newFilterAlert.Enabled),
128-
RunAsUserID: graphql.String(newFilterAlert.RunAsUserID),
129-
QueryOwnershipType: humiographql.QueryOwnershipType(newFilterAlert.QueryOwnershipType),
125+
ViewName: humiographql.RepoOrViewName(viewName),
126+
Name: graphql.String(newFilterAlert.Name),
127+
Description: graphql.String(newFilterAlert.Description),
128+
QueryString: graphql.String(newFilterAlert.QueryString),
129+
ActionIdsOrNames: actionNames,
130+
Labels: labels,
131+
Enabled: graphql.Boolean(newFilterAlert.Enabled),
132+
ThrottleTimeSeconds: humiographql.Long(newFilterAlert.ThrottleTimeSeconds),
133+
ThrottleField: graphql.String(newFilterAlert.ThrottleField),
134+
RunAsUserID: graphql.String(newFilterAlert.RunAsUserID),
135+
QueryOwnershipType: humiographql.QueryOwnershipType(newFilterAlert.QueryOwnershipType),
130136
}
131137

132138
variables := map[string]any{
@@ -209,14 +215,16 @@ func mapHumioGraphqlFilterAlertToFilterAlert(input humiographql.FilterAlert) Fil
209215
}
210216

211217
return FilterAlert{
212-
ID: string(input.ID),
213-
Name: string(input.Name),
214-
Description: string(input.Description),
215-
QueryString: string(input.QueryString),
216-
ActionNames: actionNames,
217-
Labels: labels,
218-
Enabled: bool(input.Enabled),
219-
QueryOwnershipType: queryOwnershipType,
220-
RunAsUserID: runAsUserID,
218+
ID: string(input.ID),
219+
Name: string(input.Name),
220+
Description: string(input.Description),
221+
QueryString: string(input.QueryString),
222+
ActionNames: actionNames,
223+
Labels: labels,
224+
Enabled: bool(input.Enabled),
225+
ThrottleTimeSeconds: int(input.ThrottleTimeSeconds),
226+
ThrottleField: string(input.ThrottleField),
227+
QueryOwnershipType: queryOwnershipType,
228+
RunAsUserID: runAsUserID,
221229
}
222230
}

api/internal/humiographql/filter-alerts.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,47 @@ import (
55
)
66

77
type FilterAlert struct {
8-
ID graphql.String `graphql:"id"`
9-
Name graphql.String `graphql:"name"`
10-
Description graphql.String `graphql:"description"`
11-
QueryString graphql.String `graphql:"queryString"`
12-
Actions []Action `graphql:"actions"`
13-
Labels []graphql.String `graphql:"labels"`
14-
Enabled graphql.Boolean `graphql:"enabled"`
15-
QueryOwnership QueryOwnership `graphql:"queryOwnership"`
8+
ID graphql.String `graphql:"id"`
9+
Name graphql.String `graphql:"name"`
10+
Description graphql.String `graphql:"description"`
11+
QueryString graphql.String `graphql:"queryString"`
12+
Actions []Action `graphql:"actions"`
13+
Labels []graphql.String `graphql:"labels"`
14+
Enabled graphql.Boolean `graphql:"enabled"`
15+
ThrottleTimeSeconds Long `graphql:"throttleTimeSeconds"`
16+
ThrottleField graphql.String `graphql:"throttleField"`
17+
QueryOwnership QueryOwnership `graphql:"queryOwnership"`
1618
}
1719

1820
type Action struct {
1921
Name graphql.String `graphql:"name"`
2022
}
2123

2224
type CreateFilterAlert struct {
23-
ViewName RepoOrViewName `json:"viewName"`
24-
Name graphql.String `json:"name"`
25-
Description graphql.String `json:"description,omitempty"`
26-
QueryString graphql.String `json:"queryString"`
27-
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
28-
Labels []graphql.String `json:"labels"`
29-
Enabled graphql.Boolean `json:"enabled"`
30-
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
31-
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
25+
ViewName RepoOrViewName `json:"viewName"`
26+
Name graphql.String `json:"name"`
27+
Description graphql.String `json:"description,omitempty"`
28+
QueryString graphql.String `json:"queryString"`
29+
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
30+
Labels []graphql.String `json:"labels"`
31+
Enabled graphql.Boolean `json:"enabled"`
32+
ThrottleTimeSeconds Long `json:"throttleTimeSeconds"`
33+
ThrottleField graphql.String `json:"throttleField"`
34+
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
35+
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
3236
}
3337

3438
type UpdateFilterAlert struct {
35-
ViewName RepoOrViewName `json:"viewName"`
36-
ID graphql.String `json:"id"`
37-
Name graphql.String `json:"name"`
38-
Description graphql.String `json:"description,omitempty"`
39-
QueryString graphql.String `json:"queryString"`
40-
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
41-
Labels []graphql.String `json:"labels"`
42-
Enabled graphql.Boolean `json:"enabled"`
43-
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
44-
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
39+
ViewName RepoOrViewName `json:"viewName"`
40+
ID graphql.String `json:"id"`
41+
Name graphql.String `json:"name"`
42+
Description graphql.String `json:"description,omitempty"`
43+
QueryString graphql.String `json:"queryString"`
44+
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
45+
Labels []graphql.String `json:"labels"`
46+
Enabled graphql.Boolean `json:"enabled"`
47+
ThrottleTimeSeconds Long `json:"throttleTimeSeconds"`
48+
ThrottleField graphql.String `json:"throttleField"`
49+
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
50+
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
4551
}

cmd/humioctl/filter_alerts_list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ func newFilterAlertsListCmd() *cobra.Command {
4343
format.String(filterAlert.Description),
4444
format.String(strings.Join(filterAlert.ActionNames, ", ")),
4545
format.String(strings.Join(filterAlert.Labels, ", ")),
46+
format.Int(filterAlert.ThrottleTimeSeconds),
47+
format.String(filterAlert.ThrottleField),
4648
format.String(filterAlert.RunAsUserID),
4749
format.String(filterAlert.QueryOwnershipType),
4850
}
4951
}
5052

51-
printOverviewTable(cmd, []string{"ID", "Name", "Enabled", "Description", "Actions", "Labels", "Run As User ID", "Query Ownership Type"}, rows)
53+
printOverviewTable(cmd, []string{"ID", "Name", "Enabled", "Description", "Actions", "Labels", "Throttle Time Seconds", "Throttle Field", "Run As User ID", "Query Ownership Type"}, rows)
5254
},
5355
}
5456

cmd/humioctl/filter_alerts_show.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func newFilterAlertsShowCmd() *cobra.Command {
5454
{format.String("Query String"), format.String(filterAlert.QueryString)},
5555
{format.String("Labels"), format.String(strings.Join(filterAlert.Labels, ", "))},
5656
{format.String("Actions"), format.String(strings.Join(filterAlert.ActionNames, ", "))},
57+
{format.String("Throttle Time Seconds"), format.Int(filterAlert.ThrottleTimeSeconds)},
58+
{format.String("Throttle Field"), format.String(filterAlert.ThrottleField)},
5759
{format.String("Run As User ID"), format.String(filterAlert.RunAsUserID)},
5860
{format.String("Query Ownership Type"), format.String(filterAlert.QueryOwnershipType)},
5961
}

0 commit comments

Comments
 (0)