@@ -10,7 +10,7 @@ internal class ClickhouseApmService : IApmService
10
10
private readonly ITraceService _traceService ;
11
11
private readonly static object lockObj = new ( ) ;
12
12
private static Dictionary < string , string > serviceOrders = new ( ) {
13
- { nameof ( ServiceListDto . Name ) , "ServiceName" } ,
13
+ { nameof ( ServiceListDto . Name ) , SERVICE_NAME } ,
14
14
{ nameof ( ServiceListDto . Envs ) , "env" } ,
15
15
{ nameof ( ServiceListDto . Latency ) , "latency" } ,
16
16
{ nameof ( ServiceListDto . Throughput ) , "throughput" } ,
@@ -19,7 +19,7 @@ internal class ClickhouseApmService : IApmService
19
19
20
20
private static Dictionary < string , string > endpointOrders = new ( ) {
21
21
{ nameof ( EndpointListDto . Name ) , "`Attributes.http.target`" } ,
22
- { nameof ( EndpointListDto . Service ) , "ServiceName" } ,
22
+ { nameof ( EndpointListDto . Service ) , SERVICE_NAME } ,
23
23
{ nameof ( EndpointListDto . Method ) , "`method`" } ,
24
24
{ nameof ( EndpointListDto . Latency ) , "latency" } ,
25
25
{ nameof ( EndpointListDto . Throughput ) , "throughput" } ,
@@ -33,6 +33,7 @@ internal class ClickhouseApmService : IApmService
33
33
{ nameof ( ErrorMessageDto . Total ) , "`total`" }
34
34
} ;
35
35
const double MILLSECOND = 1e6 ;
36
+ const string SERVICE_NAME = "ServiceName" ;
36
37
37
38
public ClickhouseApmService ( MasaStackClickhouseConnection dbConnection , ITraceService traceService )
38
39
{
@@ -50,7 +51,7 @@ public Task<PaginatedListBase<ServiceListDto>> ServicePageAsync(BaseApmRequestDt
50
51
var groupby = "group by ServiceName" ;
51
52
var countSql = $ "select count(1) from(select count(1) from { Constants . TraceTableFull } where { where } { groupby } )";
52
53
PaginatedListBase < ServiceListDto > result = new ( ) { Total = Convert . ToInt64 ( Scalar ( countSql , parameters ) ) } ;
53
- var orderBy = GetOrderBy ( query , serviceOrders , defaultSort : "ServiceName" ) ;
54
+ var orderBy = GetOrderBy ( query , serviceOrders , defaultSort : SERVICE_NAME ) ;
54
55
var sql = $@ "select * from(
55
56
select
56
57
ServiceName,
@@ -76,7 +77,7 @@ public Task<PaginatedListBase<EndpointListDto>> InstancePageAsync(BaseApmRequest
76
77
var selectField = $@ "ResourceAttributesValues[indexOf(ResourceAttributesKeys,'service.instance.id')] instance`,
77
78
AVG(Duration/{ MILLSECOND } ) Latency,
78
79
count(1)*1.0/DATEDIFF(MINUTE ,toDateTime(@startTime),toDateTime (@endTime)) throughput
79
- sum(has(['{ string . Join ( ',' , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))/count(1) failed" ;
80
+ sum(has(['{ string . Join ( " ','" , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))/count(1) failed" ;
80
81
return GetEndpointAsync ( query , groupBy , selectField , reader => new EndpointListDto ( )
81
82
{
82
83
Name = reader [ 0 ] . ToString ( ) ! ,
@@ -92,7 +93,7 @@ public Task<PaginatedListBase<EndpointListDto>> DependencyPageAsync(BaseApmReque
92
93
var selectField = $@ "`Attributes.http.target`,ServiceName,SpanAttributesValues[indexOf(SpanAttributesKeys,'http.method')] `method`,
93
94
AVG(Duration{ MILLSECOND } ) Latency,
94
95
count(1)*1.0/DATEDIFF(MINUTE ,toDateTime(@startTime),toDateTime (@endTime)) throughput
95
- sum(has(['{ string . Join ( ',' , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))/count(1) failed" ;
96
+ sum(has(['{ string . Join ( " ','" , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))/count(1) failed" ;
96
97
return GetEndpointAsync ( query , groupBy , selectField , ConvertEndpointDto ) ;
97
98
}
98
99
@@ -114,7 +115,7 @@ public Task<PaginatedListBase<EndpointListDto>> EndpointPageAsync(BaseApmRequest
114
115
var selectField = $@ "`Attributes.http.target`,ServiceName,SpanAttributesValues[indexOf(SpanAttributesKeys,'http.method')] `method`,
115
116
floor(AVG(Duration/{ MILLSECOND } )) latency,
116
117
round(count(1)*1.0/DATEDIFF(MINUTE ,toDateTime(@startTime),toDateTime (@endTime)),2) throughput,
117
- round(sum(has(['{ string . Join ( ',' , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))*100.0/count(1),2) failed" ;
118
+ round(sum(has(['{ string . Join ( " ','" , query . GetErrorStatusCodes ( ) ) } '],`Attributes.http.status_code`))*100.0/count(1),2) failed" ;
118
119
return GetEndpointAsync ( query , groupBy , selectField , ConvertEndpointDto ) ;
119
120
}
120
121
@@ -136,9 +137,10 @@ public Task<IEnumerable<ChartLineDto>> ChartDataAsync(BaseApmRequestDto query)
136
137
query . IsServer = true ;
137
138
var ( where , parameters ) = AppendWhere ( query ) ;
138
139
var result = new List < ChartLineDto > ( ) ;
139
- var groupby = "group by ServiceName ,`time` order by ServiceName ,`time`" ;
140
+ var field = query is ApmEndpointRequestDto apmEndpointDto && string . IsNullOrEmpty ( apmEndpointDto . Endpoint ) ? "Attributes.http.target" : SERVICE_NAME ;
141
+ var groupby = $ "group by { field } ,`time` order by { field } ,`time`";
140
142
var sql = $@ "select
141
- ServiceName ,
143
+ { field } ,
142
144
toStartOfInterval(`Timestamp` , INTERVAL { GetPeriod ( query ) } ) as `time`,
143
145
floor(avg(Duration/{ MILLSECOND } )) `latency`,
144
146
floor(quantile(0.95)(Duration/{ MILLSECOND } )) `p95`,
@@ -464,7 +466,7 @@ public Task<IEnumerable<ChartLineCountDto>> GetErrorChartAsync(ApmEndpointReques
464
466
var sql = $@ "select
465
467
toStartOfInterval(`Timestamp` , INTERVAL { GetPeriod ( query ) } ) as `time`,
466
468
count(1) `total`
467
- from { Constants . LogTableFull } where { where } and SeverityText='Error' { groupby } " ;
469
+ from { Constants . LogTableFull } where { where } and SeverityText='Error' and `Attributes.exception.message`!='' { groupby } " ;
468
470
469
471
return Task . FromResult ( getChartCountData ( sql , parameters , query . ComparisonType ) . AsEnumerable ( ) ) ;
470
472
}
0 commit comments