(ctx context.Context, start time.Time, end time.Time, wheres []monitor.MonWhereItem)
| 201 | } |
| 202 | |
| 203 | func (e *executor) InvokeTrend(ctx context.Context, start time.Time, end time.Time, wheres []monitor.MonWhereItem) (*monitor.MonInvokeCountTrend, string, error) { |
| 204 | newStartTime, every, windowOffset, bucket := getTimeIntervalAndBucket(start, end) |
| 205 | filters := formatFilter(wheres) |
| 206 | |
| 207 | requestConditions := []string{"total", "success", "2xx", "s4xx", "s5xx"} |
| 208 | |
| 209 | dates, requestValues, err := e.fluxQuery.CommonTendency(ctx, e.openApi, newStartTime, end, bucket, "request", filters, requestConditions, every, windowOffset, flux.SumFn) |
| 210 | if err != nil { |
| 211 | return nil, "", err |
| 212 | } |
| 213 | requestRate := make([]float64, 0, len(dates)) |
| 214 | //计算请求成功率 |
| 215 | requestTotal := requestValues["total"] |
| 216 | requestSuccess := requestValues["success"] |
| 217 | for i, total := range requestTotal { |
| 218 | if total == 0 { |
| 219 | requestRate = append(requestRate, 0) |
| 220 | continue |
| 221 | } |
| 222 | rate := FormatFloat64(float64(requestSuccess[i])/float64(total), 4) |
| 223 | requestRate = append(requestRate, rate) |
| 224 | } |
| 225 | |
| 226 | proxyConditions := []string{"p_total", "p_success"} |
| 227 | |
| 228 | _, proxyValues, err := e.fluxQuery.CommonTendency(ctx, e.openApi, newStartTime, end, bucket, "proxy", filters, proxyConditions, every, windowOffset, flux.SumFn) |
| 229 | if err != nil { |
| 230 | return nil, "", err |
| 231 | } |
| 232 | //计算转发成功率 |
| 233 | proxyTotal := proxyValues["p_total"] |
| 234 | proxySuccess := proxyValues["p_success"] //proxySuccess和proxyTotal必定等长 |
| 235 | proxyRate := make([]float64, 0, len(proxyTotal)) |
| 236 | for i, total := range proxyTotal { |
| 237 | if total == 0 { |
| 238 | proxyRate = append(proxyRate, 0) |
| 239 | continue |
| 240 | } |
| 241 | rate := FormatFloat64(float64(proxySuccess[i])/float64(total), 4) |
| 242 | proxyRate = append(proxyRate, rate) |
| 243 | } |
| 244 | resultVal := &monitor.MonInvokeCountTrend{ |
| 245 | Date: dates, |
| 246 | Status5XX: requestValues["s5xx"], |
| 247 | Status4XX: requestValues["s4xx"], |
| 248 | ProxyRate: proxyRate, |
| 249 | ProxyTotal: proxyValues["p_total"], |
| 250 | RequestRate: requestRate, |
| 251 | RequestTotal: requestValues["total"], |
| 252 | } |
| 253 | |
| 254 | return resultVal, every, nil |
| 255 | } |
| 256 | |
| 257 | func (e *executor) summary(ctx context.Context, start, end time.Time, bucket string, filters string, filterCfg *flux.StatisticsFilterConf, prefix string) (*monitor.Summary, error) { |
| 258 | //获取请求表的饼状图 |
nothing calls this directly
no test coverage detected