query:=fmt.Sprintf("SELECT serviceName, quantile(0.99)(durationNano) as p99, avg(durationNano) as avgDuration, count(*) as numCalls FROM %s WHERE timestamp>='%s' AND timestamp<='%s' AND kind='2' GROUP BY serviceName ORDER BY p99 DESC",r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
query=fmt.Sprintf("SELECT serviceName, count(*) as numErrors FROM %s WHERE timestamp>='%s' AND timestamp<='%s' AND kind='2' AND statusCode>=500 GROUP BY serviceName",r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
////////////////// Below block gets 4xx of services
service4xxItems:=[]model.ServiceItem{}
query=fmt.Sprintf("SELECT serviceName, count(*) as num4xx FROM %s WHERE timestamp>='%s' AND timestamp<='%s' AND kind='2' AND statusCode>=400 AND statusCode<500 GROUP BY serviceName",r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, quantile(0.99)(durationNano) as p99, quantile(0.95)(durationNano) as p95,quantile(0.50)(durationNano) as p50, count(*) as numCalls FROM %s WHERE timestamp>='%s' AND timestamp<='%s' AND kind='2' AND serviceName='%s' GROUP BY time ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10),queryParams.ServiceName)
err:=r.db.Select(&serviceOverviewItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, count(*) as numErrors FROM %s WHERE timestamp>='%s' AND timestamp<='%s' AND kind='2' AND serviceName='%s' AND statusCode>=500 GROUP BY time ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10),queryParams.ServiceName)
err=r.db.Select(&serviceErrorItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, avg(durationNano) as avgDuration, count(1) as numCalls, dbSystem FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' AND kind='3' AND dbName IS NOT NULL GROUP BY time, dbSystem ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, avg(durationNano) as avgDuration FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' AND kind='3' AND externalHttpUrl IS NOT NULL GROUP BY time ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
err:=r.db.Select(&serviceExternalItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, avg(durationNano) as avgDuration, count(1) as numCalls, externalHttpUrl FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' AND kind='3' AND externalHttpUrl IS NOT NULL AND statusCode >= 500 GROUP BY time, externalHttpUrl ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
queryTotal:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, avg(durationNano) as avgDuration, count(1) as numCalls, externalHttpUrl FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' AND kind='3' AND externalHttpUrl IS NOT NULL GROUP BY time, externalHttpUrl ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %s minute) as time, avg(durationNano) as avgDuration, count(1) as numCalls, externalHttpUrl FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' AND kind='3' AND externalHttpUrl IS NOT NULL GROUP BY time, externalHttpUrl ORDER BY time DESC",strconv.Itoa(int(queryParams.StepSeconds/60)),r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
err:=r.db.Select(&serviceExternalItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query:=fmt.Sprintf("SELECT quantile(0.5)(durationNano) as p50, quantile(0.95)(durationNano) as p95, quantile(0.99)(durationNano) as p99, COUNT(1) as numCalls, name FROM %s WHERE timestamp >= '%s' AND timestamp <= '%s' AND kind='2' and serviceName='%s' GROUP BY name",r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10),queryParams.ServiceName)
err:=r.db.Select(&topEndpointsItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %d HOUR) as time, count(1) as count FROM %s WHERE serviceName='%s' AND timestamp>='%s' AND timestamp<='%s' GROUP BY time ORDER BY time ASC",queryParams.StepHour,r.indexTable,queryParams.ServiceName,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
}else{
query=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %d HOUR) as time, count(1) as count FROM %s WHERE timestamp>='%s' AND timestamp<='%s' GROUP BY time ORDER BY time ASC",queryParams.StepHour,r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
}
err:=r.db.Select(&usageItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query:=fmt.Sprintf(`SELECT DISTINCT arrayJoin(tagsKeys) as tagKeys FROM %s WHERE serviceName='%s' AND toDate(timestamp) > now() - INTERVAL 1 DAY`,r.indexTable,serviceName)
err:=r.db.Select(&tagItems,query)
zap.S().Info(query)
iferr!=nil{
zap.S().Debug("Error in processing sql query: ",err)
returnnil,fmt.Errorf("Error in processing sql query")
query:=fmt.Sprintf(`SELECT spanID, parentSpanID, serviceName FROM %s WHERE timestamp>='%s' AND timestamp<='%s'`,r.indexTable,strconv.FormatInt(queryParams.Start.UnixNano(),10),strconv.FormatInt(queryParams.End.UnixNano(),10))
aggregation_query=" quantile(0.50)(durationNano) as value "
break
case"p95":
aggregation_query=" quantile(0.95)(durationNano) as value "
break
case"p99":
aggregation_query=" quantile(0.99)(durationNano) as value "
break
}
}elseifqueryParams.Dimension=="calls"{
aggregation_query=" count(*) as value "
}
query:=fmt.Sprintf("SELECT toStartOfInterval(timestamp, INTERVAL %d minute) as time, %s FROM %s WHERE timestamp >= ? AND timestamp <= ?",queryParams.StepSeconds/60,aggregation_query,r.indexTable)