Skip to content

Commit

Permalink
feat: error msg根据body进行截取,url传递和查询
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng committed Apr 16, 2024
1 parent af5368a commit 0ac209e
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ private static void InitErrorTable(MasaStackClickhouseConnection connection)
`ServiceName` String CODEC(ZSTD(1)),
`Resource.service.namespace` String CODEC(ZSTD(1)),
`Attributes.http.target` String CODEC(ZSTD(1)),
INDEX idx_log_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_log_spanid SpanId TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_log_environment `Resource.service.namespace` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_log_servicename ServiceName TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_log_type `Attributes.exception.type` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_log_endpoint `Attributes.http.target` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_string_message `Attributes.exception.message` TYPE tokenbf_v1(30720, 2, 0) GRANULARITY 1
`MsgGroupKey` String CODEC(ZSTD(1)),
INDEX idx_error_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_spanid SpanId TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_environment `Resource.service.namespace` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_servicename ServiceName TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_type `Attributes.exception.type` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_endpoint `Attributes.http.target` TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX idx_error_message `Attributes.exception.message` TYPE tokenbf_v1(30720, 2, 0) GRANULARITY 1,
INDEX idx_error_msggroupkey MsgGroupKey TYPE bloom_filter(0.001) GRANULARITY 1
)
ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (Timestamp,
ServiceName,
`Resource.service.namespace`,
`Attributes.exception.type`,
`MsgGroupKey`,
`Attributes.http.target`)
TTL toDateTime(Timestamp) + toIntervalDay(30)
SETTINGS index_granularity = 8192,
Expand All @@ -46,8 +50,11 @@ TTL toDateTime(Timestamp) + toIntervalDay(30)
$@"CREATE MATERIALIZED VIEW {Constants.ErrorTable.Replace(".",".v_")} TO {Constants.ErrorTable}
AS
SELECT
Timestamp,TraceId,SpanId, Body AS `Attributes.exception.message`,LogAttributes['exception.type'] AS `Attributes.exception.type`,
ServiceName,ResourceAttributes['service.namespace'] AS `Resource.service.namespace`, LogAttributes['RequestPath'] AS `Attributes.http.target`
Timestamp,TraceId,SpanId, if(position(Body, '\n') > 0,extract(Body, '[^\n\r]+'),Body) `Attributes.exception.message`,LogAttributes['exception.type'] AS `Attributes.exception.type`,
ServiceName,ResourceAttributes['service.namespace'] AS `Resource.service.namespace`, LogAttributes['RequestPath'] AS `Attributes.http.target`,
multiIf(
length(`Attributes.exception.message`)-150<=0,`Attributes.exception.message`,
extract(`Attributes.exception.message`, '[^,:\\.£º£¬\{{\[]+')) AS MsgGroupKey
FROM {MasaStackClickhouseConnection.LogSourceTable}
WHERE mapContains(LogAttributes, 'exception.type')
"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ public Task<PaginatedListBase<ErrorMessageDto>> ErrorMessagePageAsync(ApmEndpoin
query.IsServer = default;
var (where, parameters) = AppendWhere(query);
var groupby = $"group by Type,Message{(string.IsNullOrEmpty(query.Endpoint) ? "" : ",Endpoint")}";
var countSql = $"select count(1) from (select Attributes.exception.type as Type,Attributes.exception.message as Message,max(Timestamp) time,count(1) from {Constants.ErrorTable} where {where} {groupby})";
var countSql = $"select count(1) from (select `Attributes.exception.type` as Type,MsgGroupKey as Message,max(Timestamp) time,count(1) from {Constants.ErrorTable} where {where} {groupby})";
PaginatedListBase<ErrorMessageDto> result = new() { Total = Convert.ToInt64(Scalar(countSql, parameters)) };
var orderBy = GetOrderBy(query, errorOrders);
var sql = $@"select * from( select Attributes.exception.type as Type,Attributes.exception.message as Message,max(Timestamp) time,count(1) total from {Constants.ErrorTable} where {where} {groupby} {orderBy} @limit)";
var sql = $@"select * from( select `Attributes.exception.type` as Type,MsgGroupKey as Message,max(Timestamp) time,count(1) total from {Constants.ErrorTable} where {where} {groupby} {orderBy} @limit)";
SetData(sql, parameters, result, query, reader => new ErrorMessageDto()
{
Type = reader[0]?.ToString()!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ private static void AddClickHouse()
if (ConfigConst.StorageConst.HasInit || !ConfigConst.IsClickhouse) return;
if (string.IsNullOrEmpty(ConfigConst.ClikhouseConnection)) return;
_services.AddMASAStackApmClickhouse(ConfigConst.ClikhouseConnection, ConfigConst.ClickhouseTableSuffix, ConfigConst.ClickHouseLogSourceTable, ConfigConst.ClickHouseTaceSourceTable);
//_services.AddMASAStackApmClickhouse(
// "Compress=True;CheckCompressedHash=False;Compressor=lz4;SocketTimeout=10000;Host=10.130.0.106;Port=4229;User=ss;Password=Ckapp@2023;Database=lonsid_fusion",
// "masav1",
// "otel_logs_masa",
// "otel_traces_masa");
ConfigConst.StorageConst.SetClickhouse();
}

Expand Down
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 Nest;

namespace Masa.Tsc.Service.Admin.Infrastructure.Const;

internal class ConfigConst
Expand Down
4 changes: 4 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 @@ -20,6 +20,10 @@ public class SearchData
public ApmComparisonTypes ComparisonType { get; set; }

public long Timestamp { get; set; }

public string ExceptionType { get; set; }

public string ExceptionMsg { get; set; }
}

public enum ApmComparisonTypes
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Apm/ErrorDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
<div class="pt-4">
<div class="text-black Body-1 pt-4">@I18n.Apm("Error.Detail.Message")</div>
<div class="ex_context pl-8 py-4 Body-2 text-black">@currentLog?.Attributes["exception.message"]</div>
<div class="ex_context pl-8 py-4 Body-2 text-black">@currentLog?.Body</div>
</div>
</MCardSubtitle>
<MCardText>
Expand Down
13 changes: 6 additions & 7 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Apm/ErrorDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ protected override void OnInitialized()

if (!string.IsNullOrEmpty(exceptionType))
{
//append.AppendFormat(" and exception.type='{0}'", exceptionType);
append.AppendFormat(" and LogAttributesValues[indexOf(LogAttributesKeys,'exception.type')]='{0}'", exceptionType);
append.AppendFormat(" and `Attributes.exception.type`='{0}'", exceptionType);
}
//if (!string.IsNullOrEmpty(exceptionMessage))
//{
// append.AppendFormat(" and LogAttributesValues[indexOf(LogAttributesKeys,'exception.message')]='{0}'", exceptionMessage);
//}
if (string.IsNullOrEmpty(Search.Text))
if (!string.IsNullOrEmpty(exceptionMessage))
{
append.AppendFormat(" and `Body` like '%{0}%'", exceptionMessage.Replace("x2E", ".").Replace("'", "''"));
}
if (string.IsNullOrEmpty(Search.Text) && append.Length > 0)
append.Remove(0, 5);
Search.Text = append.ToString();
}
Expand Down
7 changes: 6 additions & 1 deletion src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Apm/Errors.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
else if (context.Header.Value == nameof(ErrorMessageDto.Message))
{
<div style="width:400px" class="text-truncate">
@context.Item.Message
<a target="_blank"
style="text-decoration:none"
title="@context.Item.Message"
href="/apm/errors/@(HttpUtility.UrlEncode(context.Item.Message).Replace(".","x2E")+GetUrlParam(service:Search.Service,env: GetSearchEnv(Search.Environment), comparisonType: Search.ComparisonType, start: Search.Start, end: Search.End,exType:context.Item.Type,exMsg:context.Item.Message,search:Search.Text))">
@context.Item.Message
</a>
</div>
}
else if (context.Header.Value == nameof(ErrorMessageDto.LastTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</ItemColContent>
</SDataTable>
<MCard Rounded=true Class="px-6" Style="border-top-left-radius: 0 !important; border-top-right-radius: 0 !important;">
<SPagination Class="mt-2" @bind-Page="page" @bind-PageSize=defaultSize Total=total PageSizeSelect="@(new List<int>{defaultSize})" />
<SPagination Class="mt-2" Page="page" PageSize=defaultSize Total=total PageSizeSelect="@(new List<int>{defaultSize})" OnChange="OnPageChange" />
</MCard>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ private async Task LoadASync(SearchData data = null)
return;
}
StateHasChanged();
await LoadPageDataAsync();
isTableLoading = false;
await LoadPageDataAsync();
StateHasChanged();
await LoadChartDataAsync();
}
Expand Down Expand Up @@ -107,6 +106,14 @@ private async Task LoadPageDataAsync()
}));
}
total = (int)result.Total;
isTableLoading = false;
}

private async Task OnPageChange((int page, int pageSize) pageData)
{
page = pageData.page;
defaultSize = pageData.pageSize;
await LoadPageDataAsync();
}

private async Task LoadChartDataAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
else if (context.Header.Value == nameof(ErrorMessageDto.Message))
{
<div style="width:400px" class="text-truncate">
@context.Item.Message
<div style="width:400px" class="text-truncate">
<a target="_blank"
style="text-decoration:none"
title="@context.Item.Message"
href="/apm/errors/@(HttpUtility.UrlEncode(context.Item.Message).Replace(".","x2E")+GetUrlParam(service:Search.Service,env: GetSearchEnv(Search.Environment), comparisonType: Search.ComparisonType, start: Search.Start, end: Search.End,exType:context.Item.Type,exMsg:context.Item.Message,search:Search.Text))">
@context.Item.Message
</a>
</div>
</div>
}
@if (context.Header.Value == nameof(ErrorMessageDto.LastTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</ItemColContent>
</SDataTable>
<MCard Rounded=true Class="px-6" Style="border-top-left-radius: 0 !important; border-top-right-radius: 0 !important;">
<SPagination Class="mt-2" @bind-Page="page" @bind-PageSize=defaultSize Total=total PageSizeSelect="@(new List<int>{defaultSize})" />
<SPagination Class="mt-2" @bind-Page="page" @bind-PageSize=defaultSize Total=total PageSizeSelect="@(new List<int>{defaultSize})" OnChange="OnPageChange" />
</MCard>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ private async Task LoadAsync(SearchData data = null)
{
return;
}
await LoadPageDataAsync();
isTableLoading = false;
await LoadPageDataAsync();
}

private async Task LoadChartDataAsync()
Expand Down Expand Up @@ -114,6 +113,14 @@ private async Task LoadPageDataAsync()
data.AddRange(result.Result);
}
total = (int)result.Total;
isTableLoading = false;
}

private async Task OnPageChange((int page, int pageSize) pageData)
{
page = pageData.page;
defaultSize = pageData.pageSize;
await LoadPageDataAsync();
}

private EChartType ConvertLatencyChartData(List<ChartLineCountDto> data, string lineColor = null, string areaLineColor = null, string? unit = null, string? lineName = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace Masa.Tsc.Web.Admin.Rcl.Pages.Apm.Services
@* @namespace Masa.Tsc.Web.Admin.Rcl.Pages.Apm.Services
@inherits ApmComponentBase
<SDataTable Headers="headers"
Expand Down Expand Up @@ -78,4 +78,4 @@
</SDataTable>
<MCard Rounded=true Class="px-6" Style="border-top-left-radius: 0 !important; border-top-right-radius: 0 !important;">
<SPagination Class="mt-2" @bind-Page="page" @bind-PageSize=defaultSize Total=total PageSizeSelect="@(new List<int>{defaultSize})" />
</MCard>
</MCard> *@
Loading

0 comments on commit 0ac209e

Please sign in to comment.