Skip to content

Commit

Permalink
fix: Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
litleleprikon committed May 27, 2020
1 parent 7caac9b commit d3be627
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 214 deletions.
2 changes: 1 addition & 1 deletion api/controller/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func saveTrigger(dataBase moira.Database, trigger *moira.Trigger, triggerID stri
if err != database.ErrNil {
for metric := range lastCheck.Metrics {
if _, ok := timeSeriesNames[metric]; !ok {
delete(lastCheck.Metrics, metric)
lastCheck.RemoveMetricState(metric)
}
}
} else {
Expand Down
63 changes: 0 additions & 63 deletions database/redis/compatibility26.go

This file was deleted.

134 changes: 0 additions & 134 deletions database/redis/compatibility26_test.go

This file was deleted.

26 changes: 14 additions & 12 deletions datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,20 @@ type MaintenanceCheck interface {

// CheckData represents last trigger check data
type CheckData struct {
Metrics map[string]MetricState `json:"metrics"`
MetricsToTargetRelation map[string]string `json:"metrics_to_target_relation"`
Score int64 `json:"score"`
State State `json:"state"`
Maintenance int64 `json:"maintenance,omitempty"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
Timestamp int64 `json:"timestamp,omitempty"`
EventTimestamp int64 `json:"event_timestamp,omitempty"`
LastSuccessfulCheckTimestamp int64 `json:"last_successful_check_timestamp"`
Suppressed bool `json:"suppressed,omitempty"`
SuppressedState State `json:"suppressed_state,omitempty"`
Message string `json:"msg,omitempty"`
Metrics map[string]MetricState `json:"metrics"`
// MetricsToTargetRelation is a map that holds relation between metric names that was alone during last
// check and targets that fetched this metric
MetricsToTargetRelation map[string]string `json:"metrics_to_target_relation"`
Score int64 `json:"score"`
State State `json:"state"`
Maintenance int64 `json:"maintenance,omitempty"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
Timestamp int64 `json:"timestamp,omitempty"`
EventTimestamp int64 `json:"event_timestamp,omitempty"`
LastSuccessfulCheckTimestamp int64 `json:"last_successful_check_timestamp"`
Suppressed bool `json:"suppressed,omitempty"`
SuppressedState State `json:"suppressed_state,omitempty"`
Message string `json:"msg,omitempty"`
}

// RemoveMetricState is a function that removes MetricState from map of states.
Expand Down
1 change: 1 addition & 0 deletions senders/webhook/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type payload struct {
Trigger triggerData `json:"trigger"`
Events []eventData `json:"events"`
Contact contactData `json:"contact"`
Plot string `json:"plot"` // Compatibility with Moira < 2.6.0
Plots []string `json:"plots"`
Throttled bool `json:"throttled"`
}
Expand Down
10 changes: 8 additions & 2 deletions senders/webhook/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ func (sender *Sender) buildRequest(events moira.NotificationEvents, contact moir
}

func buildRequestBody(events moira.NotificationEvents, contact moira.ContactData, trigger moira.TriggerData, plots [][]byte, throttled bool) ([]byte, error) {
encodedFirstPlot := ""
encodedPlots := make([]string, 0, len(plots))
for _, plot := range plots {
encodedPlots = append(encodedPlots, bytesToBase64(plot))
for i, plot := range plots {
encodedPlot := bytesToBase64(plot)
encodedPlots = append(encodedPlots, encodedPlot)
if i == 0 {
encodedFirstPlot = encodedPlot
}
}
requestPayload := payload{
Trigger: toTriggerData(trigger),
Expand All @@ -47,6 +52,7 @@ func buildRequestBody(events moira.NotificationEvents, contact moira.ContactData
ID: contact.ID,
User: contact.User,
},
Plot: encodedFirstPlot,
Plots: encodedPlots,
Throttled: throttled,
}
Expand Down
6 changes: 4 additions & 2 deletions senders/webhook/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const expectedStateChangePayload = `
"value": "contactValue",
"id": "contactID",
"user": "contactUser"
},
},
"plot": "",
"plots": [],
"throttled": false
}
Expand All @@ -117,7 +118,8 @@ const expectedEmptyPayload = `
"value": "",
"id": "",
"user": ""
},
},
"plot": "",
"plots": [],
"throttled": false
}
Expand Down

0 comments on commit d3be627

Please sign in to comment.