Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: show app not relation by maui httprquest traces #476

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ internal static class IDbConnectionExtensitions
{
public static PaginatedListBase<TraceResponseDto> QueryTrace(this IDbConnection connection, BaseRequestDto query)
{
if (query.Conditions != null && query.Conditions.Any(c => c.Name == "MAUI"))
{
var list = query.Conditions.ToList();
list.RemoveAll((c => c.Name == "MAUI"));
return QueryMAUITrace(connection, query);
}
var (where, parameters, ors) = AppendWhere(query);
var orderBy = AppendOrderBy(query, false);
var result = new PaginatedListBase<TraceResponseDto>() { Result = new() };
Expand All @@ -27,6 +33,34 @@ public static PaginatedListBase<TraceResponseDto> QueryTrace(this IDbConnection
return result;
}

private static PaginatedListBase<TraceResponseDto> QueryMAUITrace(this IDbConnection connection, BaseRequestDto query)
{
var (where, parameters, ors) = AppendWhere(query);
var orderBy = AppendOrderBy(query, false);
var result = new PaginatedListBase<TraceResponseDto>() { Result = new() };
var start = (query.Page - 1) * query.PageSize;
if (query.HasPage())
{
var countSql1 = CombineOrs($"select TraceId from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where}", ors);
var countSql2 = CombineOrs($"select TraceId from {MasaStackClickhouseConnection.TraceHttpClientTable} where {where} and ParentSpanId not in(select SpanId from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where})", ors);
var countSql = $"select count(1) as `total` from ({countSql1} union all {countSql2})";
var total = Convert.ToInt64(ExecuteScalar(connection, $"select sum(`total`) from ({countSql})", parameters?.ToArray()));
result.Total = total;
if (total <= 0 || start - total >= 0)
return result;
}

var querySql1 = CombineOrs($"select ServiceName,{ClickhouseHelper.GetName("timestamp", false)},TraceId,SpanId,ParentSpanId,TraceState,SpanKind,Duration,SpanName,Spans,Resources from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where}", ors, orderBy);
var querySql2 = CombineOrs($"select ServiceName,{ClickhouseHelper.GetName("timestamp", false)},TraceId,SpanId,ParentSpanId,TraceState,SpanKind,Duration,SpanName,Spans,Resources from {MasaStackClickhouseConnection.TraceHttpClientTable} where {where} and ParentSpanId not in(select SpanId from {MasaStackClickhouseConnection.TraceHttpServerTable} where {where})", ors, orderBy);
var querySql = $"({querySql1} union all {querySql2})";
result.Result = Query(connection, $"select * from {querySql} as t {orderBy} limit {start},{query.PageSize}", parameters?.ToArray(), ConvertTraceDto);

return result;

}



public static PaginatedListBase<LogResponseDto> QueryLog(this IDbConnection connection, BaseRequestDto query)
{
var (where, parameters, ors) = AppendWhere(query, false);
Expand Down
12 changes: 6 additions & 6 deletions src/Services/Masa.Tsc.Service.Admin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@

#if DEBUG
redis = builder.Environment.EnvironmentName == "Development" ? AppSettings.GetModel<RedisConfigurationOptions>("LocalRedisOptions") : redisOption;
builder.Services.AddDaprStarter(opt =>
{
opt.AppId = appid;
opt.DaprHttpPort = 3606;
opt.DaprGrpcPort = 3607;
});
//builder.Services.AddDaprStarter(opt =>
//{
// opt.AppId = appid;
// opt.DaprHttpPort = 3606;
// opt.DaprGrpcPort = 3607;
//});
#else
redis = redisOption;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
TItem="ValueTuple<string,string>"
TValue="string"
TItemValue="string"
ItemText="@(item=>string.IsNullOrEmpty(item.Item2)?item.Item1:$"{item.Item1} {item.Item2}")"
ItemText="item=>item.Item1"
ItemValue="item=>item.Item1"
Disabled="isServiceLoading"
Small
Expand All @@ -73,7 +73,17 @@
Loading="isServiceLoading"
Clearable
Class="rounded-2 mr-1"
Style="max-width:250px" />
Style="max-width:250px">
<ItemContent>
<div class="d-flex justify-space-between m-list-item__title">
<div>@context.Item.Item1</div>
@if (!string.IsNullOrEmpty(context.Item.Item2))
{
<div style="color:#BDBDBD" class="pl-2">@context.Item.Item2</div>
}
</div>
</ItemContent>
</SAutoComplete>

@if (ShowComparison)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<MTab Value="2">@I18n.Apm("Tabs.Errors")</MTab>
<MTab Value="3">@I18n.Apm("Tabs.Logs")</MTab>
<div class="d-flex justify-end" style="width:calc(100% - 300px)">
<div class="pr-4 pt-4">@GetService(Search.Service!)?.AppDescription</div>
<div class="pr-4 pt-4" style="color:#BDBDBD">@GetService(Search.Service!)?.AppDescription</div>
</div>
</MTabs>
<CascadingValue Value="Search">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<MTab Value="3">@I18n.Apm("Tabs.Errors")</MTab>
<MTab Value="4">@I18n.Apm("Tabs.Logs")</MTab>
<div class="d-flex justify-end" style="width:calc(100% - 400px)">
<div class="pr-4 pt-4">@GetService(Search.Service!)?.AppDescription</div>
<div class="pr-4 pt-4" style="color:#BDBDBD">@GetService(Search.Service!)?.AppDescription</div>
</div>
</MTabs>
<CascadingValue Value="Search">
Expand Down
27 changes: 20 additions & 7 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/App/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
TItem="ValueTuple<string,string>"
TValue="string"
TItemValue="string"
ItemText="@(item=>$"{item.Item1}{(string.IsNullOrEmpty(item.Item2)?string.Empty:$" {item.Item2}")}")"
ItemText="item=>item.Item1"
ItemValue="item=>item.Item1"
BackgroundColor="white"
Style="@("width:220px")"
Class="@("user-auto-complete pr-2")"
Placeholder="应用" Label="应用" Clearable />
Placeholder="应用" Label="应用" Clearable>
<ItemContent>
<div class="d-flex justify-space-between m-list-item__title">
<div>@context.Item.Item1</div>
@if (!string.IsNullOrEmpty(context.Item.Item2))
{
<div style="color:#BDBDBD" class="pl-2">@context.Item.Item2</div>
}
</div>
</ItemContent>
</SAutoComplete>

<STextField Small Clearable Value="_searchText" ValueChanged="SearchValueChange" TValue="string" BackgroundColor="white" OnEnter="OnErrorChanged" Label="报错关键信息" Placeholder="报错关键信息" Style="@("width:280px")" Class="rounded-2" />
</div>
Expand Down Expand Up @@ -47,12 +57,13 @@
<!--left-->
<div class="col-3 white rounded-lg py-0">
<div class="py-4">
<SButton OnClick="Top" BorderRadiusClass="rounded-lg" Class="px-10">顶部</SButton>
<SButton OnClick="Pre" BorderRadiusClass="rounded-lg" Class="pl-4 px-10"> 前一分钟</SButton>
<SButton OnClick="Top" BorderRadiusClass="rounded-lg" Class="px-4">顶部</SButton>
<SButton OnClick="Pre" BorderRadiusClass="rounded-lg" Class="ml-2 px-4"> 前一分钟</SButton>
<SButton OnClick="ShowHideHttpTrace" BorderRadiusClass="rounded-lg" Class="ml-2 px-4"> @btnText</SButton>
</div>
@if (dataLoading)
{
<LoadingData DefaultClass=false Style="@("height:calc(100vh - 378px)")" Class="full-width" />
<LoadingData DefaultClass="false" Style="@("height:calc(100vh - 378px)")" Class="full-width" />
}
else
{
Expand All @@ -63,8 +74,8 @@
</MVirtualScroll>
}
<div class="py-4">
<SButton OnClick="Bottom" BorderRadiusClass="rounded-lg px-10">尾部</SButton>
<SButton OnClick="Next" BorderRadiusClass="rounded-lg px-10" Class="pl-4"> 后一分钟</SButton>
<SButton OnClick="Bottom" BorderRadiusClass="rounded-lg px-4">尾部</SButton>
<SButton OnClick="Next" BorderRadiusClass="rounded-lg px-4" Class="ml-4"> 后一分钟</SButton>
</div>
</div>
<!--end left-->
Expand Down Expand Up @@ -128,6 +139,8 @@

private void RenderTraces(RenderTreeBuilder __builder, OperationLineTraceModel item)
{
if (!showNormalClient && item.Data.Kind != "SPAN_KIND_SERVER" && !item.IsError)
return;
bool isSelected = currentLog == null && currentTrace != null && item == currentTrace;
bool isSearchMatched = IsSearchKeyword(item);
var color = item.IsError ? "red" : isSelected ? "yellow lighten-2" : isSearchMatched ? "orange lighten-2" : "light-green lighten-2";
Expand Down
13 changes: 13 additions & 0 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/App/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ private async Task LoadTrace(bool isPre = false, bool isNext = false, int second
Page = 1,
PageSize = 200,
Conditions = new List<FieldConditionDto> {
//app特有查询
new FieldConditionDto{
Name="MAUI"
},
new FieldConditionDto{
Name =StorageConst.Current.Trace.UserId,
Type= ConditionTypes.Equal,
Expand Down Expand Up @@ -522,6 +526,15 @@ private async Task Share()
await PopupService.EnqueueSnackbarAsync("分享连接复制成功", AlertTypes.Success, true);
}

string btnText = "不显示正常HTTP";
bool showNormalClient = false;
private void ShowHideHttpTrace()
{
showNormalClient = !showNormalClient;
btnText = showNormalClient ? "显示所有HTTP" : "不显示正常HTTP";
StateHasChanged();
}

private async Task Top()
{
await ChangeCurrent(data[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public string Url
{
return url.ToString()!;
}
if (Data.Kind != "SPAN_KIND_SERVER" && Data.Attributes.TryGetValue("http.url", out url) && !string.IsNullOrEmpty(url?.ToString()))
{
return url.ToString()!;
}
return "未匹配到路由";
}
}
Expand All @@ -55,7 +59,19 @@ public string Url
/// </summary>
public List<LogResponseDto> Logs { get; set; } = new();

public bool IsError => Logs.Exists(log => log.SeverityText == "Error" && !log.Body.ToString()!.Contains("Event") && (log.Attributes.ContainsKey("exception.type") || log.Attributes.ContainsKey("exception.message")));
public bool IsError
{
get
{
if (Data.Attributes.TryGetValue("http.status_code", out var status))
{
var code = status.ToString();
if (string.IsNullOrEmpty(code) || code.Length - 3 < 0) return true;
return code == "400" || code[0] == '5' && code != "599";
}
return Logs.Exists(log => log.SeverityText == "Error" && !log.Body.ToString()!.Contains("Event") && (log.Attributes.ContainsKey("exception.type") || log.Attributes.ContainsKey("exception.message")));
}
}
}

public class OperationLineLogModel
Expand Down