Commit 1e271a68 authored by John Jarvis's avatar John Jarvis

Jarv/update report

parent 40f21ad2
......@@ -4,14 +4,17 @@
[[projects]]
branch = "master"
name = "github.com/GeertJohan/go.rice"
packages = [".","embedded"]
packages = [
".",
"embedded"
]
revision = "c02ca9a983da5807ddf7d796784928f5be4afd09"
[[projects]]
branch = "master"
name = "github.com/PagerDuty/go-pagerduty"
packages = ["."]
revision = "078a3284fb0ee5256d2164b53b9ed44ff3b3b05e"
revision = "5f93c380e5f988559a9ed7bc11a60b3db7e06ef3"
[[projects]]
branch = "master"
......@@ -38,10 +41,10 @@
version = "v0.6.2"
[[projects]]
branch = "v2"
name = "gopkg.in/yaml.v2"
packages = ["."]
revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
version = "v2.2.1"
[solve-meta]
analyzer-name = "dep"
......
......@@ -38,6 +38,7 @@ type Project struct {
// Projects for project ids
type Projects struct {
Infrastructure Project `yaml:"infrastructure"`
Production Project `yaml:"production"`
ReportProject Project `yaml:"report_project"`
}
......
......@@ -39,6 +39,11 @@ func main() {
if config.Projects.Infrastructure.ID == 0 {
log.Fatalln("ERROR: It looks like you have an old settings file, please update using oncall-settings-example.yaml")
}
if config.Projects.Production.ID == 0 {
log.Fatalln("ERROR: It looks like you have an old settings file, you are missing the production project ID. please update using oncall-settings-example.yaml")
}
opts := oncall.ReportOptions{}
report := oncall.NewReport(config, opts)
title := "OnCall report for period: " +
......
......@@ -3,6 +3,7 @@ package oncall
import (
"fmt"
"log"
"strings"
"time"
gitlab "github.com/xanzy/go-gitlab"
......@@ -10,26 +11,29 @@ import (
// GitLabHelper api helper
type GitLabHelper struct {
client *gitlab.Client
apiToken string
projectID int
dayOffset int
client *gitlab.Client
apiToken string
projectID int
projectIDProd int
dayOffset int
}
// GitLabHelperOptions options for the api helper
type GitLabHelperOptions struct {
APIToken string
ProjectID int
DayOffset int
APIToken string
ProjectID int
ProjectIDProd int
DayOffset int
}
// NewGitLabHelper creates a new api helper
func NewGitLabHelper(opts GitLabHelperOptions) *GitLabHelper {
r := GitLabHelper{
client: newGitLabClient(opts.APIToken),
apiToken: opts.APIToken,
projectID: opts.ProjectID,
dayOffset: opts.DayOffset,
client: newGitLabClient(opts.APIToken),
apiToken: opts.APIToken,
projectID: opts.ProjectID,
projectIDProd: opts.ProjectIDProd,
dayOffset: opts.DayOffset,
}
return &r
}
......@@ -88,6 +92,30 @@ func (g *GitLabHelper) GetIssuesOpenedDuringShift() []*gitlab.Issue {
return allIssues
}
// GetIssuesOpenedDuringShiftProd gets opened issues during shift for production issues
func (g *GitLabHelper) GetIssuesOpenedDuringShiftProd() []*gitlab.Issue {
var opts gitlab.ListProjectIssuesOptions
opts.ListOptions.PerPage = 100
dayInterval := time.Now().UTC().AddDate(0, 0, -g.dayOffset)
opts.CreatedAfter = &dayInterval
allIssues := make([]*gitlab.Issue, 0)
for {
issues, r, err := g.client.Issues.ListProjectIssues(g.projectIDProd, &opts)
if err != nil {
panic(err)
}
for _, issue := range issues {
allIssues = append(allIssues, issue)
}
if r.NextPage == 0 {
break
}
log.Println("Setting next page to ", r.NextPage)
opts.ListOptions.Page = r.NextPage
}
return allIssues
}
// GetIssuesOpenAll gets all open issues
func (g *GitLabHelper) GetIssuesOpenAll() []*gitlab.Issue {
var opts gitlab.ListProjectIssuesOptions
......@@ -112,6 +140,30 @@ func (g *GitLabHelper) GetIssuesOpenAll() []*gitlab.Issue {
return allIssues
}
// GetIssuesOpenAllProd gets all open issues in production
func (g *GitLabHelper) GetIssuesOpenAllProd() []*gitlab.Issue {
var opts gitlab.ListProjectIssuesOptions
opts.ListOptions.PerPage = 100
state := "opened"
opts.State = &state
allIssues := make([]*gitlab.Issue, 0)
for {
issues, r, err := g.client.Issues.ListProjectIssues(g.projectIDProd, &opts)
if err != nil {
panic(err)
}
for _, issue := range issues {
allIssues = append(allIssues, issue)
}
if r.NextPage == 0 {
break
}
log.Println("Getting next page from response", r.NextPage)
opts.ListOptions.Page = r.NextPage
}
return allIssues
}
// UploadFile uploads a file to a project
func (g *GitLabHelper) UploadFile(projectID int, fname string) *gitlab.ProjectFile {
pf, _, err := g.client.Projects.UploadFile(projectID, fname)
......@@ -121,6 +173,16 @@ func (g *GitLabHelper) UploadFile(projectID int, fname string) *gitlab.ProjectFi
return pf
}
func filterSeverityLabels(labels []string) (filteredLabels []string) {
// severityTest := func(s string) bool { return strings.HasPrefix(s, "S") && len(s) <= 2 }
for _, l := range labels {
if strings.HasPrefix(l, "S") && len(l) <= 2 {
filteredLabels = append(filteredLabels, l)
}
}
return
}
func filterIssuesByLabel(label string, issues []*gitlab.Issue) (filteredIssues []*gitlab.Issue) {
for _, p := range issues {
if stringInSlice(label, p.Labels) {
......@@ -140,6 +202,15 @@ func filterIssuesByState(state string, issues []*gitlab.Issue) (filteredIssues [
return
}
func choose(ss []string, test func(string) bool) (ret []string) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
......
This diff is collapsed.
......@@ -26,7 +26,9 @@ func getOncallIncidents(config *config.Config) []pagerduty.Incident {
var opts pagerduty.ListIncidentsOptions
opts.ServiceIDs = []string{config.PagerDuty.ServiceID}
opts.Since = nowPdDateWithOffset(-config.DayOffset)
var list pagerduty.APIListObject
list.Limit = 100
opts.APIListObject = list
if incs, err := client.ListIncidents(opts); err != nil {
panic(err)
} else {
......
......@@ -20,14 +20,17 @@ type IssueStats struct {
Critical int
Outage int
CorrectiveAction int
Change int
Incident int
}
// Issue for oncall labeled issues
type Issue struct {
Summary string
URL string
CreatedAt string
Assignee string
Summary string
URL string
CreatedAt string
Assignee string
SeverityLabels []string
}
// Incident for PD incident
......@@ -42,8 +45,12 @@ type TemplateData struct {
WeeklyOpsGraphs []WeeklyOpsGraph
TeamMembers []TeamMember
Incidents []Incident
OnCallIssues []Issue
OpenOnCallIssues []Issue
OpenChangeIssues []Issue
OpenIncidentIssues []Issue
CriticalIssues []Issue
ChangeIssues []Issue
IncidentIssues []Issue
OutageIssues []Issue
CorrectiveActionIssues []Issue
IncidentCount int
......
......@@ -7,6 +7,7 @@
{{- end}}
## PagerDuty Incidents
* Number of incidents: **{{.IncidentCount}}**
| Created | Summary |
......@@ -16,39 +17,68 @@
| [{{.CreatedAt}}]({{.URL}}) | {{.Summary}} |
{{- end }}
## Issues
### Open Issue Stats
### 7 Day OnCall 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}}**
* Oncall issues : **{{.IssuesOpenedDuringShift.OnCall}}**
* Access Request : **{{.IssuesOpenedDuringShift.AccessRequest}}**
* Critical : **{{.IssuesOpenedDuringShift.Critical}}**
* Outage : **{{.IssuesOpenedDuringShift.Outage}}**
* Corrective Action : **{{.IssuesOpenedDuringShift.CorrectiveAction}}**
### Open OnCall Issue Stats
#### Open Change Issues
* [Oncall issues](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=oncall) : **{{.IssuesOpenAll.OnCall}}**
* [Access Request](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=access%20request) : **{{.IssuesOpenAll.AccessRequest}}**
* [Critical](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=critical) : **{{.IssuesOpenAll.Critical}}**
* [Outage](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=outage) : **{{.IssuesOpenAll.Outage}}**
* [Corrective Action](https://gitlab.com/gitlab-com/infrastructure/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=corrective%20action) : **{{.IssuesOpenAll.CorrectiveAction}}**
| Created | Assignee | Summary |
| ------ | -------- | ------- |
{{- range .OpenChangeIssues }}
| [{{.CreatedAt}}]({{.URL}}) | {{.Assignee }} | {{.Summary}} |
{{- end }}
### Open Oncall Issues
#### Open Incident Issues
| Created | Assignee | Summary |
| ------ | ---------| ------- |
| ------ | -------- | ------- |
{{- range .OnCallIssues }}
{{- range .OpenIncidentIssues }}
| [{{.CreatedAt}}]({{.URL}}) | {{.Assignee }} | {{.Summary}} |
{{- end }}
## Weekly Ops
{{- range .WeeklyOpsGraphs}}
### {{ .Name }}
![]({{.URL}})
#### Open Oncall Issues
| Created | Assignee | Summary |
| ------ | -------- | ------- |
{{- range .OpenOnCallIssues }}
| [{{.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
| Created | Assignee | Summary |
| ------ | -------- | ------- |
{{- range .ChangeIssues }}
| [{{.CreatedAt}}]({{.URL}}) | {{.Assignee }} | {{.Summary}} |
{{- end }}
#### Incident Issues
| Created | Assignee | Summary | Severity |
| ------ | -------- | ------- | ------- |
{{- range .IncidentIssues }}
| [{{.CreatedAt}}]({{.URL}}) | {{.Assignee }} | {{.Summary}} | {{range .SeverityLabels}}~{{.}}{{ end }} |
{{- end }}
{{- 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