123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package models
- const (
- //apdex:ms,rate:min
- APDEXANDREDSQL = `SELECT AppAlias as app_alias,
- countIf(Duration <= ? * 1000 *1000 ) AS satisfied,
- countIf(Duration > ? * 1000 * 1000 AND Duration <= ? * 1000 * 1000 ) AS tolerable,
- countIf(Duration > ? * 1000 * 1000 ) AS frustrated,
- (satisfied + tolerable / 2.0 ) / (satisfied + tolerable + frustrated) AS apdex,
- count(*) as totalRequests,
- (totalRequests / ?) as rate,
- countIf(SpanAttributes['http.status_code'] >= '400' or SpanAttributes['http.response.status_code'] >= '400') / totalRequests as errorRate,
- (sum(Duration) / totalRequests / (1000 * 1000)) as latency
- FROM otel.otel_traces
- WHERE Timestamp >= now() - INTERVAL ? MINUTE AND (ParentSpanId = '')
- AND AppAlias IN (?)
- GROUP BY AppAlias;
- `
- SERVICEAPDEXANDREDSQL = `SELECT AppAlias as app_alias,
- countIf(Duration <= %d * 1000 *1000 ) AS satisfied,
- countIf(Duration > %d * 1000 * 1000 AND Duration <= %d * 1000 * 1000 ) AS tolerable,
- countIf(Duration > %d * 1000 * 1000 ) AS frustrated,
- (satisfied + tolerable / 2.0 ) / (satisfied + tolerable + frustrated) AS apdex,
- count(*) as totalRequests,
- (totalRequests / %d) as rate,
- countIf(SpanAttributes['http.status_code'] >= '400' or SpanAttributes['http.response.status_code'] >= '400') / totalRequests as errorRate,
- (sum(Duration) / totalRequests / (1000 * 1000)) as latency
- FROM otel.otel_traces
- WHERE Timestamp >= ? AND Timestamp <= ? AND (ParentSpanId = '')
- AND AppAlias = ?
- AND ServiceName = ?
- GROUP BY AppAlias;
- `
- )
- //AND (SpanKind != 'SPAN_KIND_CLIENT')
- type ReqApp struct {
- AppId int `json:"app_id"`
- AppAlias string `uri:"app_alias" json:"app_alias"`
- AppName string `json:"app_name"`
- PolicyT map[string]interface{} `json:"policy_t"` //私有匹配策略,暂时不提供,后续开启业务个性化配置时开放,当前默认继承ScoreParams中的PolicyT
- }
- type ScoreParams struct {
- ReqAppList []ReqApp `json:"req_applist"`
- Interval int32 `json:"interval"` //最小分钟级 1min
- PolicyT map[string]interface{} `json:"policy_t"` //公共匹配策略 apdex_a: 1500(ms), apdex_b: 2500(ms) **duration单位为ns
- }
- type ServiceScoreParams struct {
- AppAlias string `uri:"app_alias" json:"app_alias"`
- SourceService string `json:"source_service" uri:"source_service" form:"source_service"`
- TargetService string `json:"target_service" uri:"target_service" form:"target_service"`
- TimeRange
- PolicyT map[string]interface{} `json:"policy_t"` //公共匹配策略 apdex_a: 1500(ms), apdex_b: 2500(ms) **duration单位为ns
- }
- type AppScore struct {
- // AppId int `json:"app_id"`
- // AppName string `json:"app_name"`
- AppAlias string `json:"app_alias" ch:"app_alias"`
- Satisfied uint64 `json:"satisfied" ch:"satisfied"` //满意请求
- Tolerable uint64 `json:"tolerable" ch:"tolerable"` //可接受请求
- Frustrated uint64 `json:"frustrated" ch:"frustrated"` //不满意请求
- TotalRequests uint64 `json:"totalRequests" ch:"totalRequests"`
- Apdex float64 `json:"apdex" ch:"apdex"`
- Rate float64 `json:"rate" ch:"rate"`
- ErrorRate float64 `json:"errorRate" ch:"errorRate"`
- Latency float64 `json:"latency" ch:"latency"`
- }
- type AppScoreList struct {
- Scores []AppScore `json:"scores"`
- }
- type AppInterval struct {
- AppAlias string `uri:"app_alias" json:"app_alias"`
- ServiceName string `uri:"service_name" form:"service_name" json:"service_name"`
- TimeRange
- AppPercentileRange
- }
- type AppServiceInterval struct {
- AppAlias string `uri:"app_alias" json:"app_alias"`
- SourceService string `uri:"source_service" json:"source_service" form:"source_service"`
- TargetService string `uri:"target_service" json:"target_service" form:"target_service"`
- TimeRange
- AppPercentileRange
- }
- // type TraceDuration struct {
- // Ts uint32 `json:"ts" ch:"ts"`
- // Duration int64 `json:"duration" ch:"Duration"`
- // HttpCode int32 `json:"http_code" ch:"HttpCode"`
- // // TraceId string `json:"traceId" ch:"TraceId"`
- // }
- type AppLatencyByInterval struct {
- Success []CoordinatePoint `json:"success"`
- Failed []CoordinatePoint `json:"failed"`
- }
|