Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng committed Mar 11, 2024
1 parent 944e371 commit 8dd8ee9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using System.Text.RegularExpressions;

namespace Masa.Contrib.StackSdks.Tsc.Apm.Clickhouse.Cliclhouse;

internal class ClickhouseApmService : IApmService
Expand Down Expand Up @@ -106,15 +104,7 @@ public Task<PaginatedListBase<EndpointListDto>> DependencyPageAsync(BaseApmReque
count(1)*1.0/DATEDIFF(MINUTE ,toDateTime(@startTime),toDateTime (@endTime)) throughput
sum(has(['{string.Join(",'", query.GetErrorStatusCodes())}'],`Attributes.http.status_code`))/count(1) failed
from {where} {groupby} {orderBy} @limit)";
SetData(sql, parameters, result, query, reader => new EndpointListDto()
{
Name = reader[0].ToString()!,
Service = reader[1]?.ToString()!,
Method = reader[2]?.ToString()!,
Latency = (long)Math.Floor(Convert.ToDouble(reader[3])),
Throughput = Math.Round(Convert.ToDouble(reader[4]), 2),
Failed = Math.Round(Convert.ToDouble(reader[5]), 2)
});
SetData(sql, parameters, result, query, ConvertEndpointDto);
return Task.FromResult(result);
}

Expand All @@ -131,16 +121,21 @@ public Task<PaginatedListBase<EndpointListDto>> EndpointPageAsync(BaseApmRequest
round(count(1)*1.0/DATEDIFF(MINUTE ,toDateTime(@startTime),toDateTime (@endTime)),2) throughput,
round(sum(has(['{string.Join("','", query.GetErrorStatusCodes())}'],`Attributes.http.status_code`))*100.0/count(1),2) failed
from {Constants.TraceTableFull} where {where} and Attributes.http.target!='' {groupby} {orderBy} @limit)";
SetData(sql, parameters, result, query, reader => new EndpointListDto()
SetData(sql, parameters, result, query, ConvertEndpointDto);
return Task.FromResult(result);
}

private EndpointListDto ConvertEndpointDto(IDataReader reader)
{
return new EndpointListDto()
{
Name = reader[0].ToString()!,
Service = reader[1]?.ToString()!,
Method = reader[2]?.ToString()!,
Latency = (long)Math.Floor(Convert.ToDouble(reader[3])),
Throughput = Math.Round(Convert.ToDouble(reader[4]), 2),
Failed = Math.Round(Convert.ToDouble(reader[5]), 2)
});
return Task.FromResult(result);
};
}

public Task<IEnumerable<ChartLineDto>> ChartDataAsync(BaseApmRequestDto query)
Expand Down Expand Up @@ -451,10 +446,20 @@ private void SetParameters(IEnumerable<IDbDataParameter> parameters)
return $"order by {defaultSort}{(isDesc ? " desc" : "")}";
}

public void Dispose()
void IDisposable.Dispose()
{
_dbConnection.Close();
_dbConnection.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool isDisposing)
{
if (isDisposing)
{
_dbConnection.Close();
_dbConnection.Dispose();
GC.SuppressFinalize(this);
}
}

public Task<IEnumerable<ChartLineCountDto>> GetErrorChartAsync(ApmEndpointRequestDto query)
Expand Down Expand Up @@ -642,5 +647,5 @@ public Task<IEnumerable<ChartPointDto>> GetTraceErrorsAsync(ApmEndpointRequestDt
}
}
return Task.FromResult(list.AsEnumerable());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
global using Masa.Contrib.StackSdks.Tsc.Apm.Clickhouse.Models.Response;
global using Masa.Contrib.StackSdks.Tsc.Clickhouse;
global using Masa.Utils.Models;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.Extensions.Logging;
global using System.Data;
global using System.Data.Common;
global using System.Runtime.CompilerServices;
global using System.Text;
global using System.Text.RegularExpressions;

0 comments on commit 8dd8ee9

Please sign in to comment.