Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
"k8s.io/klog"
)

const (
MaxIncidentWindow = timeseries.Day
)

type LoadWorldF func(ctx context.Context, project *db.Project, from, to timeseries.Time) (*model.World, error)

type Api struct {
Expand Down Expand Up @@ -580,7 +584,7 @@ func (api *Api) PanelData(w http.ResponseWriter, r *http.Request, u *db.User) {
}
}

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

from, to, _ := api.getTimeContext(r)
from, to, _, truncated := api.getTimeContext(r)
world, cacheStatus, err := api.LoadWorld(r.Context(), project, from, to)
if world == nil {
step := increaseStepForBigDurations(from, to, 15*timeseries.Second)
world = model.NewWorld(from, to.Add(-step), step, step)
}
world.Ctx.Truncated = truncated
return world, project, cacheStatus, err
}

func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time, incident *model.ApplicationIncident) {
func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time, incident *model.ApplicationIncident, truncated bool) {
now := timeseries.Now()
q := r.URL.Query()
from = utils.ParseTime(now, q.Get("from"), now.Add(-timeseries.Hour))
Expand All @@ -1802,6 +1807,10 @@ func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timese
} else {
to = now
}
if to.Sub(from) > MaxIncidentWindow {
from = to.Add(-MaxIncidentWindow)
truncated = true
}
}
}
return
Expand Down
2 changes: 1 addition & 1 deletion api/rca.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func (api *Api) RCA(w http.ResponseWriter, r *http.Request, u *db.User) {
rca := &model.RCA{}
projectId := db.ProjectId(mux.Vars(r)["project"])
from, to, incident := api.getTimeContext(r)
from, to, incident, _ := api.getTimeContext(r)

defer func() {
if incident != nil {
Expand Down
7 changes: 7 additions & 0 deletions model/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ type Chart struct {
}

func NewChart(ctx timeseries.Context, title string) *Chart {
if ctx.Truncated {
title += " (truncated range)"
}
return &Chart{Ctx: ctx, Title: title}
}

Expand Down Expand Up @@ -245,6 +248,10 @@ type ChartGroup struct {
}

func NewChartGroup(ctx timeseries.Context, title string) *ChartGroup {
if ctx.Truncated {
title += " (truncated range)"
ctx.Truncated = false
}
return &ChartGroup{ctx: ctx, Title: title}
}

Expand Down
9 changes: 5 additions & 4 deletions timeseries/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ const (
)

type Context struct {
From Time `json:"from"`
To Time `json:"to"`
Step Duration `json:"step"`
RawStep Duration `json:"raw_step"`
From Time `json:"from"`
To Time `json:"to"`
Step Duration `json:"step"`
RawStep Duration `json:"raw_step"`
Truncated bool `json:"truncated"`
}

func NewContext(from, to Time, step Duration) Context {
Expand Down
Loading