(ctx context.Context, start time.Time, end time.Time, measurement string, bucket string, filters string, fields []string)
| 455 | } |
| 456 | |
| 457 | func (e *executor) aggregateSummary(ctx context.Context, start time.Time, end time.Time, measurement string, bucket string, filters string, fields []string) (map[string]*monitor.Aggregate, error) { |
| 458 | if len(fields) == 0 { |
| 459 | return nil, fmt.Errorf("fields is empty") |
| 460 | } |
| 461 | maxFields := make([]string, 0, len(fields)) |
| 462 | minFields := make([]string, 0, len(fields)) |
| 463 | avgFields := make([]string, 0, len(fields)) |
| 464 | for _, field := range fields { |
| 465 | maxFields = append(maxFields, field+"_max") |
| 466 | minFields = append(minFields, field+"_min") |
| 467 | avgFields = append(avgFields, field+"_avg") |
| 468 | } |
| 469 | maxRes, err := e.fluxQuery.CommonQueryOnce(ctx, e.openApi, start, end, bucket, filters, &flux.StatisticsFilterConf{ |
| 470 | Measurement: measurement, |
| 471 | AggregateFn: "max()", |
| 472 | Fields: maxFields, |
| 473 | }) |
| 474 | if err != nil { |
| 475 | return nil, err |
| 476 | } |
| 477 | minRes, err := e.fluxQuery.CommonQueryOnce(ctx, e.openApi, start, end, bucket, filters, &flux.StatisticsFilterConf{ |
| 478 | Measurement: measurement, |
| 479 | AggregateFn: "min()", |
| 480 | Fields: minFields, |
| 481 | }) |
| 482 | if err != nil { |
| 483 | return nil, err |
| 484 | } |
| 485 | avgRes, err := e.fluxQuery.CommonQueryOnce(ctx, e.openApi, start, end, bucket, filters, &flux.StatisticsFilterConf{ |
| 486 | Measurement: measurement, |
| 487 | AggregateFn: "mean()", |
| 488 | Fields: avgFields, |
| 489 | }) |
| 490 | if err != nil { |
| 491 | return nil, err |
| 492 | } |
| 493 | result := make(map[string]*monitor.Aggregate) |
| 494 | for _, field := range fields { |
| 495 | a := new(monitor.Aggregate) |
| 496 | if v, ok := avgRes[field+"_avg"]; ok { |
| 497 | a.Avg = int64(v.(float64)) |
| 498 | } |
| 499 | if v, ok := maxRes[field+"_max"]; ok { |
| 500 | a.Max = v.(int64) |
| 501 | } |
| 502 | if v, ok := minRes[field+"_min"]; ok { |
| 503 | a.Min = v.(int64) |
| 504 | } |
| 505 | |
| 506 | result[field] = a |
| 507 | } |
| 508 | |
| 509 | return result, nil |
| 510 | |
| 511 | } |
| 512 | |
| 513 | func (e *executor) SumResponseTimeOverview(ctx context.Context, start time.Time, end time.Time, wheres []monitor.MonWhereItem) ([]time.Time, *monitor.Aggregate, []int64, error) { |
| 514 | newStartTime, every, windowOffset, bucket := getTimeIntervalAndBucket(start, end) |
no test coverage detected