- 请求新增 granularity,看板所有区块统一按所选区间统计(累计量单独保留) - 覆盖率/正确率新增区间严格口径 period_quality,趋势图覆盖整个区间 - 新增环比上一区间条数;卡片标题与统计口径随区间自动生成 - 未传 granularity 时保持原周看板行为不变 (cherry picked from commit fbb1d1d819e7b85ef849e3a1e4ef209707a67b22)
This commit is contained in:
@@ -61,6 +61,9 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
|
||||
if !s.valid() {
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
if !validDashboardGranularity(q.Granularity) {
|
||||
return out, dobotaiops.ErrInvalidQuery
|
||||
}
|
||||
if q.Window.TenantKey != s.tenant || !utf8.ValidString(q.Keyword) || utf8.RuneCountInString(q.Keyword) > 200 || strings.ContainsRune(q.Keyword, 0) {
|
||||
return out, dobotaiops.ErrInvalidQuery
|
||||
}
|
||||
@@ -221,7 +224,11 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
|
||||
}
|
||||
out.Quality = qaopsquality.Summarize(views)
|
||||
products, types, daily := map[string]int{}, map[string]int{}, map[string]int{}
|
||||
for day := out.WeekStart; day.Before(q.Window.End); day = day.AddDate(0, 0, 1) {
|
||||
dailyFrom := out.WeekStart
|
||||
if q.Granularity != "" {
|
||||
dailyFrom = q.Window.Start
|
||||
}
|
||||
for day := dailyFrom; day.Before(q.Window.End); day = day.AddDate(0, 0, 1) {
|
||||
daily[day.Format("2006-01-02")] = 0
|
||||
}
|
||||
regionIndex := map[string]int{}
|
||||
@@ -237,10 +244,18 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
|
||||
users[region.Name] = map[string]bool{}
|
||||
out.Regions = append(out.Regions, r)
|
||||
}
|
||||
inPeriod := 0
|
||||
for _, r := range records {
|
||||
if !r.at.Before(out.WeekStart) {
|
||||
out.NewThisWeek++
|
||||
daily[r.at.In(dashboardLocation).Format("2006-01-02")]++
|
||||
if q.Granularity == "" {
|
||||
if !r.at.Before(out.WeekStart) {
|
||||
out.NewThisWeek++
|
||||
daily[r.at.In(dashboardLocation).Format("2006-01-02")]++
|
||||
}
|
||||
} else if !r.at.Before(q.Window.Start) {
|
||||
inPeriod++
|
||||
if _, ok := daily[r.at.In(dashboardLocation).Format("2006-01-02")]; ok {
|
||||
daily[r.at.In(dashboardLocation).Format("2006-01-02")]++
|
||||
}
|
||||
}
|
||||
if !r.at.Before(q.Window.Start) {
|
||||
v, ok := views[r.id]
|
||||
@@ -260,10 +275,24 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
|
||||
}
|
||||
out.Products = dashboardCategories(products)
|
||||
out.IssueTypes = dashboardCategories(types)
|
||||
for day := out.WeekStart; day.Before(q.Window.End); day = day.AddDate(0, 0, 1) {
|
||||
for day := dailyFrom; day.Before(q.Window.End); day = day.AddDate(0, 0, 1) {
|
||||
date := day.Format("2006-01-02")
|
||||
out.Daily = append(out.Daily, DashboardDaily{Date: date, Count: daily[date]})
|
||||
}
|
||||
if q.Granularity != "" {
|
||||
period := dashboardPeriod(q.Granularity, q.Window.Start, q.Window.End)
|
||||
out.Granularity = q.Granularity
|
||||
out.Period = &period
|
||||
out.PeriodIssues = &inPeriod
|
||||
// Keep the historical invariant "daily sums up to new_this_week" so old
|
||||
// clients that only know this field still agree with the trend panel.
|
||||
out.NewThisWeek = inPeriod
|
||||
prev, err := s.dashboardPeriodIssues(ctx, tx, q, master, period.PrevStart, period.PrevEnd)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.PrevPeriodIssues = &prev
|
||||
}
|
||||
for i := range out.Regions {
|
||||
r := &out.Regions[i]
|
||||
if r.Users != nil {
|
||||
@@ -307,6 +336,10 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
|
||||
out.QualityPeriod = &DashboardQualityPeriod{Month: month.Format("2006-01"), Start: month, CutoffAt: cutoff, CalculatedAt: calculated, Source: dashboardMonthlySource, PolicyVersion: dashboardMonthlyPolicy}
|
||||
rates := dashboardStrictQuality(timeline, month, cutoff)
|
||||
out.MonthlyQuality = &rates
|
||||
if q.Granularity != "" {
|
||||
periodRates := dashboardStrictQuality(timeline, q.Window.Start, q.Window.End)
|
||||
out.PeriodQuality = &periodRates
|
||||
}
|
||||
out.CalendarMonths = dashboardCalendarMonths(timeline, cutoff, calculated)
|
||||
} else {
|
||||
out.CumulativeWeeks = []DashboardCumulative{}
|
||||
|
||||
Reference in New Issue
Block a user