Commit 4fea1b41 authored by John Jarvis's avatar John Jarvis

Add corrective actions to the report

* Add corrective actions to 7 day summary and open issue stats.
* Add debug flag for printing report to stdout.
parent 2f75be8e
Pipeline #31116136 failed with stage
in 1 minute and 12 seconds
......@@ -59,6 +59,7 @@ type Config struct {
OncallLabel string `yaml:"oncall_label"`
PagerDuty PagerDuty `yaml:"pagerduty"`
WeeklyOps []WeeklyOps `yaml:"weekly_ops"`
Debug bool
}
// ParseConfig parses the yaml configuration from a reader
......@@ -77,7 +78,7 @@ func ParseConfig(r io.Reader) (Config, error) {
// ReadConfig will attempt to read the different configuration
// parameters from a yaml formatted file.
func ReadConfig(f string) (*Config, error) {
func ReadConfig(f string, d bool) (*Config, error) {
var cfg Config
if _, err := os.Stat(f); os.IsNotExist(err) {
return nil, errors.New(err.Error())
......@@ -90,5 +91,6 @@ func ReadConfig(f string) (*Config, error) {
if err != nil {
return nil, errors.New(err.Error())
}
cfg.Debug = d
return &cfg, nil
}
......@@ -30,9 +30,9 @@ func main() {
}
cfgFile := flag.String("config", filepath, "the configuration file")
debug := flag.Bool("debug", false, "print the issue instead of creating it")
flag.Parse()
config, err := config.ReadConfig(*cfgFile)
config, err := config.ReadConfig(*cfgFile, *debug)
if err != nil {
log.Fatalln(err)
}
......
......@@ -55,6 +55,9 @@ func (r *Report) CreateReportIssue(title string) string {
// weeklyOpsGraphs := r.uploadGraphs(graphs)
weeklyOpsGraphs := []WeeklyOpsGraph{}
desc := r.generateTemplate(weeklyOpsGraphs)
if r.Config.Debug == true {
return desc
}
issue := r.Helpers.GitLab.CreateIssue(title, desc, r.Config.Projects.ReportProject.ID)
return issue.WebURL
}
......@@ -104,6 +107,7 @@ func (r *Report) generateTemplate(weeklyOpsGraphs []WeeklyOpsGraph) string {
templateData.IssuesOpenAll.Change = len(filterIssuesByLabel("change", allOpenIssuesProd))
templateData.IssuesOpenAll.Incident = len(filterIssuesByLabel("incident", allOpenIssuesProd))
templateData.IssuesOpenAll.AccessRequest = len(filterIssuesByLabel("access request", allOpenIssues))
templateData.IssuesOpenAll.CorrectiveAction = len(filterIssuesByLabel("corrective action", allOpenIssues))
// Open incident issues
for _, p := range filterIssuesByLabel("incident", allOpenIssuesProd) {
......@@ -126,6 +130,7 @@ func (r *Report) generateTemplate(weeklyOpsGraphs []WeeklyOpsGraph) string {
templateData.IssuesOpenedDuringShift.AccessRequest = len(filterIssuesByLabel("access request", shiftIssues))
templateData.IssuesOpenedDuringShift.Change = len(filterIssuesByLabel("change", shiftIssuesProd))
templateData.IssuesOpenedDuringShift.Incident = len(filterIssuesByLabel("incident", shiftIssuesProd))
templateData.IssuesOpenedDuringShift.CorrectiveAction = len(filterIssuesByLabel("corrective action", shiftIssuesProd))
// Shift incident issues
for _, p := range filterIssuesByLabel("incident", shiftIssuesProd) {
......@@ -137,6 +142,11 @@ func (r *Report) generateTemplate(weeklyOpsGraphs []WeeklyOpsGraph) string {
templateData.ChangeIssues = append(templateData.ChangeIssues, *genIssueInfo(p))
}
// Shift corrective action issues
for _, p := range filterIssuesByLabel("corrective action", shiftIssues) {
templateData.CorrectiveActionIssues = append(templateData.CorrectiveActionIssues, *genIssueInfo(p))
}
templateBox, err := rice.FindBox("../templates")
if err != nil {
log.Fatal(err)
......
......@@ -17,9 +17,9 @@ type IssueStats struct {
Count int
OnCall int
AccessRequest int
CorrectiveAction int
Critical int
Outage int
CorrectiveAction int
Change int
Incident int
}
......@@ -51,9 +51,9 @@ type TemplateData struct {
OpenIncidentIssues []Issue
CriticalIssues []Issue
ChangeIssues []Issue
CorrectiveActionIssues []Issue
IncidentIssues []Issue
OutageIssues []Issue
CorrectiveActionIssues []Issue
IncidentCount int
IssuesOpenAll IssueStats
IssuesOpenedDuringShift IssueStats
......
......@@ -17,12 +17,40 @@
| [{{.CreatedAt}}]({{.URL}}) | {{.Summary}} |
{{- end }}
### 7 Day Issue Stats
* Oncall issues : **{{.IssuesOpenedDuringShift.OnCall}}**
* Access Request : **{{.IssuesOpenedDuringShift.AccessRequest}}**
* Change Issues : **{{.IssuesOpenedDuringShift.Change}}**
* Incident Issues : **{{.IssuesOpenedDuringShift.Incident}}**
* CorrectiveAction Issues : **{{.IssuesOpenedDuringShift.CorrectiveAction}}**
#### Change Issues
{{- range .ChangeIssues }}
* {{.CreatedAt}} - [{{.Summary}}]({{.URL}}) - {{.Assignee }}
{{- end }}
#### Incident Issues
{{- range .IncidentIssues }}
* {{.CreatedAt}} - [{{.Summary}}]({{.URL}}) - {{.Assignee }} |{{range .SeverityLabels}} ~{{.}}{{ end }} |{{range .ServiceLabels}} ~"{{.}}"{{ end }} | `{{.URL}}`
{{- end }}
#### CorrectiveAction Issues
{{- range .CorrectiveActionIssues }}
* {{.CreatedAt}} - [{{.Summary}}]({{.URL}}) - {{.Assignee }}
{{- end }}
### Open Issue Stats
* [Oncall issues](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=oncall) : **{{.IssuesOpenAll.OnCall}}**
* [Change issues](https://gitlab.com/gitlab-com/production/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=change) : **{{.IssuesOpenAll.Change}}**
* [Incident issues](https://gitlab.com/gitlab-com/production/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=incident) : **{{.IssuesOpenAll.Incident}}**
* [Access Request](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=access%20request) : **{{.IssuesOpenAll.AccessRequest}}**
* [CorrectiveAction](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=corrective%20action) : **{{.IssuesOpenAll.CorrectiveAction}}**
#### Open Change Issues
......@@ -53,26 +81,6 @@
| [{{.CreatedAt}}]({{.URL}}) | {{.Assignee }} | {{.Summary}} |
{{- end }}
### 7 Day Issue Stats
* Oncall issues : **{{.IssuesOpenedDuringShift.OnCall}}**
* Access Request : **{{.IssuesOpenedDuringShift.AccessRequest}}**
* Change Issues : **{{.IssuesOpenedDuringShift.Change}}**
* Incident Issues : **{{.IssuesOpenedDuringShift.Incident}}**
#### Change Issues
{{- range .ChangeIssues }}
* {{.CreatedAt}} - [{{.Summary}}]({{.URL}}) - {{.Assignee }}
{{- end }}
#### Incident Issues
{{- range .IncidentIssues }}
* {{.CreatedAt}} - [{{.Summary}}]({{.URL}}) - {{.Assignee }} |{{range .SeverityLabels}} ~{{.}}{{ end }} |{{range .ServiceLabels}} ~"{{.}}"{{ end }} | `{{.URL}}`
{{- end }}
_This issue was automatically generated using [oncall-robot-assistant](https://gitlab.com/gl-infra/oncall-robot-assistant)_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment