Skip to content

Commit

Permalink
feat: add trace detail latency changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng committed Nov 15, 2024
1 parent ee56e0a commit 63e1e96
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ internal ApmService(ICaller caller) : base(caller, "/api/apm") { }

public Task<List<string>> GetExceptionTypesAsync(BaseRequestDto query) => Caller.GetByBodyAsync<List<string>>($"{RootPath}/errorTypes", query)!;

public Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmEndpointRequestDto query) => Caller.GetByBodyAsync<PaginatedListBase<SimpleTraceListDto>>($"{RootPath}/simpleTraceList", body: query)!;
public Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmTraceLatencyRequestDto query) => Caller.GetByBodyAsync<PaginatedListBase<SimpleTraceListDto>>($"{RootPath}/simpleTraceList", body: query)!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task<PaginatedListBase<TraceResponseDto>> TraceLatencyDetailAsync(A
return await _traceService.ListAsync(queryDto);
}

public async Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmEndpointRequestDto query)
public async Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmTraceLatencyRequestDto query)
{
var orderBy = GetOrderBy(query, new() { { StorageConst.Current.Timestimap, StorageConst.Current.Timestimap } });
var (where, ors, parameters) = AppendWhere(query);
Expand All @@ -323,16 +323,18 @@ public async Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync
string sql1;
if (query.IsInstrument)
{
sql1 = $"select count(1) as Total from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where}";
sql1 = $"select 1 as Total from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where}";
}
else
{
sql1 = $@"select countMerge(Total) as Total from {Constants.DurationCountTable} where {where}";
sql1 = $@"select 1 as Total from {Constants.DurationCountTable} where {where}";
}

sql1 = CombineOrs(sql1, ors);
var countSql = $"select sum(Total) from({sql1})";
SetMinDurationUnit(parameters);
result.Total = Convert.ToInt64(await Scalar(countSql, parameters));
ResetMinDurationUnit(parameters);
}

var sql = CombineOrs($@"select TraceId,Duration,Timestamp from {(query.IsInstrument ? MasaStackClickhouseConnection.TraceHttpServerTable : Constants.DurationTable)} where {where}", ors);
Expand All @@ -342,6 +344,30 @@ public async Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync
return result;
}

private void SetMinDurationUnit(List<ClickHouseParameter> parameters)
{
if (parameters == null || !parameters.Any())
return;
var param = parameters.Find(p => p.ParameterName == "minDuration");
if (param != null)
param.Value = (long)(((long)param.Value) / MILLSECOND);
param = parameters.Find(p => p.ParameterName == "maxDuration");
if (param != null)
param.Value = (long)(((long)param.Value) / MILLSECOND);
}

private void ResetMinDurationUnit(List<ClickHouseParameter> parameters)
{
if (parameters == null || !parameters.Any())
return;
var param = parameters.Find(p => p.ParameterName == "minDuration");
if (param != null)
param.Value = (long)(((long)param.Value) * MILLSECOND);
param = parameters.Find(p => p.ParameterName == "maxDuration");
if (param != null)
param.Value = (long)(((long)param.Value) * MILLSECOND);
}

private static SimpleTraceListDto ToSampleTraceListDto(IDataReader reader)
{
var startTime = Convert.ToDateTime(reader[StorageConst.Current.Timestimap]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public interface IApmService : IDisposable
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmEndpointRequestDto query);
Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceListAsync(ApmTraceLatencyRequestDto query);

Task<List<string>> GetErrorTypesAsync(BaseApmRequestDto query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class ApmTraceLatencyRequestDto : ApmEndpointRequestDto
/// </summary>
public long? LatMax { get; set; }

public new int PageSize { get; } = 1;
public new int PageSize { get; } = 500;
}
2 changes: 1 addition & 1 deletion src/Services/Masa.Tsc.Service.Admin/Services/ApmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private async Task<Dictionary<string, List<EnviromentAppDto>>> GetTeamAllEnvApps
return result;
}

public Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceList([FromServices] IApmService apmService, [FromBody] ApmEndpointRequestDto query)
public Task<PaginatedListBase<SimpleTraceListDto>> GetSimpleTraceList([FromServices] IApmService apmService, [FromBody] ApmTraceLatencyRequestDto query)
=> apmService.GetSimpleTraceListAsync(query);

public Task<List<string>> GetEndpointList([FromServices] IApmService apmService, [FromBody] BaseApmRequestDto query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public partial class ApmSearchComponent
AppTypes.Service.ToString(),
AppTypes.Job.ToString()
};

private bool Isloaded = false;

private QuickRangeKey quickRangeKey = QuickRangeKey.Last15Minutes;
private List<string> textFileds = new();

Expand All @@ -60,7 +59,7 @@ protected override async Task OnInitializedAsync()
{
await InitAsync();
}
Isloaded = true;
Search.Loaded = true;
await OnValueChanged();
StateHasChanged();
}
Expand Down Expand Up @@ -198,7 +197,7 @@ private void SetQueryList()
private void TeamChanged(Guid teamId)
{
GlobalConfig.CurrentTeamId = teamId;
if (Isloaded && CheckUrl())
if (Search.Loaded && CheckUrl())
{
NavigationManager.NavigateTo(NavigationManager.Uri, true);
return;
Expand Down Expand Up @@ -379,12 +378,12 @@ private async Task LoadErrorAsync()

private async Task OnTimeUpdate((DateTimeOffset? start, DateTimeOffset? end) times)
{
if (Isloaded || Search.Start == DateTime.MinValue)
if (Search.Loaded || Search.Start == DateTime.MinValue)
{
Search.Start = times.start!.Value.UtcDateTime;
Search.End = times.end!.Value.UtcDateTime;
}
if (Isloaded)
if (Search.Loaded)
{
await InitAsync();
await OnValueChanged();
Expand Down Expand Up @@ -473,7 +472,7 @@ private async Task OnMessageEnter()

private async Task OnValueChanged()
{
if (!Isloaded || string.IsNullOrEmpty(Value.Environment))
if (!Search.Loaded || string.IsNullOrEmpty(Value.Environment))
return;
if (ValueChanged.HasDelegate)
await ValueChanged.InvokeAsync(Value);
Expand Down
5 changes: 5 additions & 0 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Data/Apm/SearchData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public SearchData()
public string TraceId { get; set; }

public string SpanId { get; set; }

/// <summary>
/// search com
/// </summary>
public bool Loaded { get; set; }
}

public enum ApmComparisonTypes
Expand Down
15 changes: 15 additions & 0 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Extentions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ public static string FormatTime(this double millionSeconds)
return $"{minis} min{(seconds > 0 ? $"{seconds} s" : "")}";
}

public static int FormatTimeToNumber(this string s)
{
if (string.IsNullOrEmpty(s))
return 0;
if (s == "<1ms")
return 0;
if (s.EndsWith("ms"))
return Convert.ToInt32(s.Substring(0, s.Length - 2));
if (s.EndsWith(" s"))
return Convert.ToInt32(s.Substring(0, s.Length - 2)) * 60;
if (s.EndsWith(" min"))
return Convert.ToInt32(s.Substring(0, s.Length - 4)) * 360;
return default;
}

public static string FormatHistory(this DateTime time)
{
var now = DateTime.UtcNow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class EndpointDetail
private string spanId = default!;

[Parameter]
public string Name { get; set; }
public string Name { get; set; }

private void OnSearchValueChanged(SearchData data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<MCardText>
@if (!timeTypeCount.ChartLoading && timeTypeCount.HasChart)
{
<MECharts Option="@(timeTypeCount.Data)" Height="166" Style="@("width:100%")" />
<MECharts Option="@(timeTypeCount.Data)" Height="166" Style="@("width:100%")" @ref="mechart" />
}
</MCardText>
</MCard>
Expand Down
Loading

0 comments on commit 63e1e96

Please sign in to comment.