Skip to content

Commit

Permalink
fix: query bugs, timezone and ui update
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng committed Mar 22, 2024
1 parent 6593e98 commit 466c7ab
Show file tree
Hide file tree
Showing 34 changed files with 161 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<MasaFrameworkPackageVersion>1.0.1-preview.11</MasaFrameworkPackageVersion>
<MasaFrameworkPackageVersion>1.0.1-preview.13</MasaFrameworkPackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal ApmService(ICaller caller) : base(caller, "/api/apm") { }

public Task<PaginatedListBase<TraceResponseDto>> GetTraceDetailAsync(ApmTraceLatencyRequestDto query) => Caller.GetAsync<PaginatedListBase<TraceResponseDto>>($"{RootPath}/traceDetail", data: query)!;

public Task<List<ChartLineDto>> GetChartsAsync(BaseApmRequestDto query) => Caller.GetAsync<List<ChartLineDto>>($"{RootPath}/charts", data: query)!;
public Task<List<ChartLineDto>> GetChartsAsync(ApmEndpointRequestDto query) => Caller.GetAsync<List<ChartLineDto>>($"{RootPath}/charts", data: query)!;

public Task<List<ChartLineCountDto>> GetErrorChartAsync(ApmEndpointRequestDto query) => Caller.GetAsync<List<ChartLineCountDto>>($"{RootPath}/errorChart", data: query)!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public static bool IsRawQuery([NotNull] this string text, bool isElasticsearch =
return false;
}

public static DateTime ParseTime(this string str)
public static DateTime ParseUTCTime(this string str)
{
return DateTime.TryParse(str, out var time) ? time : DateTime.MinValue;
if (DateTime.TryParse(str, out var time))
{
return new DateTimeOffset(time, TimeSpan.Zero).DateTime;
}
return DateTime.MinValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public class LogPageQueryDto : Pagination<LogPageQueryDto>
public string Service { get; set; }

public string LogLevel { get; set; }

public bool IsLimitEnv { get; set; } = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public record LogsQuery(string Query, DateTime Start, DateTime End, int Page = 1
string? SpanId = null,
string? Service = null,
string? Env = null,
string? LogLevel = null) : Query<PaginatedListBase<LogResponseDto>>
string? LogLevel = null,
bool IsLimitEnv = false
) : Query<PaginatedListBase<LogResponseDto>>
{
public override PaginatedListBase<LogResponseDto> Result { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using Masa.BuildingBlocks.StackSdks.Tsc.Contracts.Model;

namespace Masa.Tsc.Service.Admin.Application.Logs;

public class QueryHandler : EnvQueryHandler
Expand Down Expand Up @@ -98,9 +100,13 @@ public async Task GetPageListAsync(LogsQuery queryData)
};
if (!isSkipEnv)
{
var env = queryData.Env == null ? GetServiceEnvironmentName(queryData.Service!) : queryData.Env;
var env = queryData.Env;
if (queryData.IsLimitEnv)
{
env = GetServiceEnvironmentName(queryData.Service!);
}
if (!string.IsNullOrEmpty(env))
query.SetEnv(env,true);
query.SetEnv(env, queryData.IsLimitEnv);
}

var data = await _logService.ListAsync(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static void SetValues(this BaseRequestDto dto)
}
}

public static void SetEnv(this BaseRequestDto dto, string envName, bool isMust = false)
public static void SetEnv(this BaseRequestDto dto, string envName, bool isMustService = true)
{
if (!isMust || string.IsNullOrEmpty(dto.Service))
if (isMustService && string.IsNullOrEmpty(dto.Service))
return;

var list = dto.Conditions?.ToList() ?? new();
Expand Down
70 changes: 43 additions & 27 deletions src/Services/Masa.Tsc.Service.Admin/Services/ApmService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using Masa.Contrib.StackSdks.Tsc.Apm.Clickhouse.Models;

namespace Masa.Tsc.Service.Admin.Services;

public class ApmService : ServiceBase
Expand All @@ -9,14 +11,15 @@ public ApmService() : base("/api/apm")
{
}

public async Task<PaginatedListBase<ServiceListDto>> GetServices([FromServices] IApmService apmService, int page, int pageSize, string start, string end, string? env, ComparisonTypes? comparisonType, string? queries, string? orderField, bool? isDesc)
public async Task<PaginatedListBase<ServiceListDto>> GetServices([FromServices] IApmService apmService, int page, int pageSize, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries, string? orderField, bool? isDesc)
=> await apmService.ServicePageAsync(new BaseApmRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
ComparisonType = comparisonType,
Queries = queries,
Service = service,
OrderField = orderField,
IsDesc = isDesc,
Page = page,
Expand All @@ -27,8 +30,8 @@ public async Task<PaginatedListBase<ServiceListDto>> GetServices([FromServices]
public async Task<PaginatedListBase<EndpointListDto>> GetEndpoints([FromServices] IApmService apmService, int page, int pageSize, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries, string? orderField, bool? isDesc)
=> await apmService.EndpointPageAsync(new BaseApmRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
ComparisonType = comparisonType,
Queries = queries,
Expand All @@ -40,23 +43,36 @@ public async Task<PaginatedListBase<EndpointListDto>> GetEndpoints([FromServices
StatusCodes = string.Join(',', ConfigConst.TraceErrorStatus)
});

public async Task<IEnumerable<ChartLineDto>> GetCharts([FromServices] IApmService apmService, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries)
=> await apmService.ChartDataAsync(new BaseApmRequestDto
public async Task<IEnumerable<ChartLineDto>> GetCharts([FromServices] IApmService apmService, string start, string end, string? env, string? service, string? endpoint, ComparisonTypes? comparisonType, string? queries)
{
BaseApmRequestDto queryDto;

if (endpoint == null)
{
Start = start.ParseTime(),
End = end.ParseTime(),
Env = GetEnv(env),
ComparisonType = comparisonType,
Queries = queries,
Service = service,
StatusCodes = string.Join(',', ConfigConst.TraceErrorStatus)
});
queryDto = new BaseApmRequestDto();
}
else
{
queryDto = new ApmEndpointRequestDto()
{
Endpoint = endpoint!
};
}
queryDto.Start = start.ParseUTCTime();
queryDto.End = end.ParseUTCTime();
queryDto.Env = GetEnv(env);
queryDto.ComparisonType = comparisonType;
queryDto.Queries = queries;
queryDto.Service = service;
queryDto.StatusCodes = string.Join(',', ConfigConst.TraceErrorStatus);
return await apmService.ChartDataAsync(queryDto);
}

public async Task<EndpointLatencyDistributionDto> GetLatencyDistributions([FromServices] IApmService apmService, string start, string end, string? env, string? service, string endpoint)
=> await apmService.EndpointLatencyDistributionAsync(new ApmEndpointRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
Service = service,
Endpoint = endpoint,
Expand All @@ -66,8 +82,8 @@ public async Task<EndpointLatencyDistributionDto> GetLatencyDistributions([FromS
public async Task<PaginatedListBase<ErrorMessageDto>> GetErrors([FromServices] IApmService apmService, int page, int pageSize, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries, string? orderField, bool? isDesc)
=> await apmService.ErrorMessagePageAsync(new ApmEndpointRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
Queries = queries,
OrderField = orderField,
Expand All @@ -80,8 +96,8 @@ public async Task<PaginatedListBase<ErrorMessageDto>> GetErrors([FromServices] I
public Task<IEnumerable<ChartPointDto>> GetSpanErrors([FromServices] IApmService apmService, int page, int pageSize, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries, string? orderField, bool? isDesc)
=> apmService.GetTraceErrorsAsync(new ApmEndpointRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
Queries = queries,
OrderField = orderField,
Expand All @@ -94,8 +110,8 @@ public Task<IEnumerable<ChartPointDto>> GetSpanErrors([FromServices] IApmService
public async Task<PaginatedListBase<TraceResponseDto>> GetTraceDetail([FromServices] IApmService apmService, int page, string start, string end, string? env, string? service, string endpoint, long? latMin, long? latMax)
=> await apmService.TraceLatencyDetailAsync(new ApmTraceLatencyRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
Page = page,
Service = service,
Expand All @@ -107,8 +123,8 @@ public async Task<PaginatedListBase<TraceResponseDto>> GetTraceDetail([FromServi
public async Task<IEnumerable<ChartLineCountDto>> GetErrorChart([FromServices] IApmService apmService, string start, string end, string? env, string? service, string? endpoint, ComparisonTypes? comparisonType, string? queries)
=> await apmService.GetErrorChartAsync(new ApmEndpointRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
ComparisonType = comparisonType,
Queries = queries,
Expand All @@ -120,8 +136,8 @@ public async Task<IEnumerable<ChartLineCountDto>> GetErrorChart([FromServices] I
public async Task<IEnumerable<ChartLineCountDto>> GetLogChart([FromServices] IApmService apmService, string start, string end, string? env, string? service, ComparisonTypes? comparisonType, string? queries)
=> await apmService.GetLogChartAsync(new ApmEndpointRequestDto
{
Start = start.ParseTime(),
End = end.ParseTime(),
Start = start.ParseUTCTime(),
End = end.ParseUTCTime(),
Env = GetEnv(env),
ComparisonType = comparisonType,
Queries = queries,
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Masa.Tsc.Service.Admin/Services/AppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<List<AppDto>> GetListAsync([FromServices] IEventBus eventBus,

public async Task<long> GetErrorCountAsync([FromServices] IEventBus eventBus, string appid, string start, string end)
{
var query = new AppErrorCountQuery(appid, start.ParseTime(), end.ParseTime());
var query = new AppErrorCountQuery(appid, start.ParseUTCTime(), end.ParseUTCTime());
await eventBus.PublishAsync(query);
return query.Result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Masa.Tsc.Service.Admin/Services/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ private async Task<IEnumerable<MappingResponseDto>> GetMappingFieldAsync([FromSe

private async Task<PaginatedListBase<LogResponseDto>> GetPageAsync([FromServices] IEventBus eventBus, LogPageQueryDto param)
{
var query = new LogsQuery(param.Query, param.Start, param.End, param.Page, param.PageSize, param.IsDesc, param.SortField, JobTaskId: param.TaskId, SpanId: param.SpanId, Service: param.Service, LogLevel: param.LogLevel, Env: param.Env);
var query = new LogsQuery(param.Query, param.Start, param.End, param.Page, param.PageSize, param.IsDesc, param.SortField, JobTaskId: param.TaskId, SpanId: param.SpanId, Service: param.Service, LogLevel: param.LogLevel, Env: param.Env, IsLimitEnv: param.IsLimitEnv);
await eventBus.PublishAsync(query);
return query.Result;
}

public async Task<List<LogErrorDto>> GetErrorTypesAsync([FromServices] IEventBus eventBus, string service, string start, string end)
{
var query = new LogErrorTypesQuery(service, start.ParseTime(), end.ParseTime());
var query = new LogErrorTypesQuery(service, start.ParseUTCTime(), end.ParseUTCTime());
await eventBus.PublishAsync(query);
return query.Result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private async Task<string> GetRangeValuesAsync([FromServices] IEventBus eventBus

public async Task<QueryResultDataResponse> GetQueryAsync([FromServices] IEventBus eventBus, [FromQuery] string query, [FromQuery] string time)
{
var result = new InstantQuery(query, time.ParseTime());
var result = new InstantQuery(query, time.ParseUTCTime());
await eventBus.PublishAsync(result);
return result.Result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Masa.Tsc.Service.Admin/Services/TraceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private async Task<IEnumerable<TraceResponseDto>> GetAsync([FromServices] IEvent

private async Task<string> GetTraceIdByMetricAsync([FromServices] IEventBus eventBus, string service, string url, string start, string end)
{
var query = new TraceIdByMetricQuery(service, url, start.ParseTime(), end.ParseTime());
var query = new TraceIdByMetricQuery(service, url, start.ParseUTCTime(), end.ParseUTCTime());
await eventBus.PublishAsync(query);
return query.Result;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ private async Task<object> AggregateAsync([FromServices] IEventBus eventBus, [Fr

public async Task<IEnumerable<TraceResponseDto>> GetNextAsync([FromServices] IEventBus eventBus, string service, string traceId, string time, string url, bool isNext)
{
var query = new TraceDetailNextQuery(service, traceId, time.ParseTime(), url, isNext);
var query = new TraceDetailNextQuery(service, traceId, time.ParseUTCTime(), url, isNext);
await eventBus.PublishAsync(query);
return query.Result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using System;

namespace Masa.Tsc.Web.Admin.Rcl.Components.Apm;

public partial class ApmSearchComponent
Expand Down Expand Up @@ -60,11 +62,14 @@ protected override async Task OnInitializedAsync()

protected override void OnInitialized()
{
Search.ComparisonType = ApmComparisonTypes.Day;
base.OnInitialized();
if (string.IsNullOrEmpty(Search.Enviroment) && string.IsNullOrEmpty(Search.Service) && !string.IsNullOrEmpty(UserContext.Environment))
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
if (string.IsNullOrEmpty(uri.Query))
{
Search.Enviroment = UserContext.Environment;
if (string.IsNullOrEmpty(Search.Enviroment) && string.IsNullOrEmpty(Search.Service) && !string.IsNullOrEmpty(UserContext.Environment))
Search.Enviroment = UserContext.Environment;
if (Search.ComparisonType == ApmComparisonTypes.None)
Search.ComparisonType = ApmComparisonTypes.Day;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<SSearch BackgroundColor="white" @bind-Value="search" Class="rounded-2" Style="border:solid 1px;width:100%" />
@if (!string.IsNullOrEmpty(LinkUrl))
{
<div class="blue rouned-lg blue rounded-lg pt-2 px-2 my-1 mx-4"> <a href="@LinkUrl" class="white--text" style="text-decoration:none" target="_blank">@I18n.Apm("Trace.Detail.SpanLog")</a></div>
<SButton Class="white--text blue darken-1 ml-4 mr-2"
Style="text-transform: none"
BorderRadiusClass="rounded-lg"
OnClick="OpenLogAsync">@I18n.Apm("Trace.Detail.SpanLog")</SButton>
}
</div>
<MSimpleTable Style="width:100%" Height="610" FixedHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Masa.Tsc.Web.Admin.Rcl.Components.Apm;

public partial class ApmTraceView
{
[Inject]
IJSRuntime JSRuntime { get; set; }

[Parameter]
public object Value { get; set; }

Expand Down Expand Up @@ -51,4 +54,9 @@ private void OnSeach(string value)
{
search = value;
}

private async Task OpenLogAsync()
{
await JSRuntime.InvokeVoidAsync("open", LinkUrl, "_blank");
}
}
3 changes: 2 additions & 1 deletion src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Apm/Endpoint.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ private async Task LoadChartDataAsync()
{
if (data.Count == 0)
return;
var query = new BaseApmRequestDto
var query = new ApmEndpointRequestDto
{
Page = page,
PageSize = defaultSize,
Start = Search.Start,
End = Search.End,
Endpoint=Search.Endpoint!,
Service = Search.Service,
Env = Search.Enviroment
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ShowEnv
ShowTime />

<MTabs FixedTabs @bind-Value="index" Class="rounded-t-xl">
<MTabs @bind-Value="index" Class="rounded-t-xl">
<MTab Value="1">@I18n.Apm("Tabs.Overview")</MTab>
<MTab Value="2">@I18n.Apm("Tabs.Errors")</MTab>
</MTabs>
Expand Down
Loading

0 comments on commit 466c7ab

Please sign in to comment.