Skip to content

Commit 11487f6

Browse files
authored
Merge pull request coroot#754 from coroot/fix_753
incidents: truncate long incident time ranges to 1 day when rendering SLI charts
2 parents 7693ef2 + 1f3a1f3 commit 11487f6

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

api/api.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232
"k8s.io/klog"
3333
)
3434

35+
const (
36+
MaxIncidentWindow = timeseries.Day
37+
)
38+
3539
type LoadWorldF func(ctx context.Context, project *db.Project, from, to timeseries.Time) (*model.World, error)
3640

3741
type Api struct {
@@ -580,7 +584,7 @@ func (api *Api) PanelData(w http.ResponseWriter, r *http.Request, u *db.User) {
580584
}
581585
}
582586

583-
from, to, _ := api.getTimeContext(r)
587+
from, to, _, _ := api.getTimeContext(r)
584588
step := increaseStepForBigDurations(from, to, maxRefreshInterval)
585589
data, err := views.Dashboards.PanelData(r.Context(), promClients, config, from, to, step)
586590
if err != nil {
@@ -1772,16 +1776,17 @@ func (api *Api) LoadWorldByRequest(r *http.Request) (*model.World, *db.Project,
17721776
return nil, nil, nil, err
17731777
}
17741778

1775-
from, to, _ := api.getTimeContext(r)
1779+
from, to, _, truncated := api.getTimeContext(r)
17761780
world, cacheStatus, err := api.LoadWorld(r.Context(), project, from, to)
17771781
if world == nil {
17781782
step := increaseStepForBigDurations(from, to, 15*timeseries.Second)
17791783
world = model.NewWorld(from, to.Add(-step), step, step)
17801784
}
1785+
world.Ctx.Truncated = truncated
17811786
return world, project, cacheStatus, err
17821787
}
17831788

1784-
func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time, incident *model.ApplicationIncident) {
1789+
func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time, incident *model.ApplicationIncident, truncated bool) {
17851790
now := timeseries.Now()
17861791
q := r.URL.Query()
17871792
from = utils.ParseTime(now, q.Get("from"), now.Add(-timeseries.Hour))
@@ -1802,6 +1807,10 @@ func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timese
18021807
} else {
18031808
to = now
18041809
}
1810+
if to.Sub(from) > MaxIncidentWindow {
1811+
from = to.Add(-MaxIncidentWindow)
1812+
truncated = true
1813+
}
18051814
}
18061815
}
18071816
return

api/rca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func (api *Api) RCA(w http.ResponseWriter, r *http.Request, u *db.User) {
1919
rca := &model.RCA{}
2020
projectId := db.ProjectId(mux.Vars(r)["project"])
21-
from, to, incident := api.getTimeContext(r)
21+
from, to, incident, _ := api.getTimeContext(r)
2222

2323
defer func() {
2424
if incident != nil {

model/chart.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ type Chart struct {
114114
}
115115

116116
func NewChart(ctx timeseries.Context, title string) *Chart {
117+
if ctx.Truncated {
118+
title += " (truncated range)"
119+
}
117120
return &Chart{Ctx: ctx, Title: title}
118121
}
119122

@@ -245,6 +248,10 @@ type ChartGroup struct {
245248
}
246249

247250
func NewChartGroup(ctx timeseries.Context, title string) *ChartGroup {
251+
if ctx.Truncated {
252+
title += " (truncated range)"
253+
ctx.Truncated = false
254+
}
248255
return &ChartGroup{ctx: ctx, Title: title}
249256
}
250257

timeseries/time.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const (
2020
)
2121

2222
type Context struct {
23-
From Time `json:"from"`
24-
To Time `json:"to"`
25-
Step Duration `json:"step"`
26-
RawStep Duration `json:"raw_step"`
23+
From Time `json:"from"`
24+
To Time `json:"to"`
25+
Step Duration `json:"step"`
26+
RawStep Duration `json:"raw_step"`
27+
Truncated bool `json:"truncated"`
2728
}
2829

2930
func NewContext(from, to Time, step Duration) Context {

0 commit comments

Comments
 (0)