-
Notifications
You must be signed in to change notification settings - Fork 116
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(tsc-sdk): add tsc-sdk for alert #125
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
36d4b69
chore: rebase resolved
Qinyouzeng 8f166e9
feat: add tsc log and metric sdk
Qinyouzeng a254f76
chore: update project
Qinyouzeng aafd4c5
feat: model names update and tests add
Qinyouzeng 51f22f5
feat : api update
Qinyouzeng e17ec3b
chore: merge
Qinyouzeng 0daba91
feat: test and update
Qinyouzeng e6d43ed
chore: tests update
Qinyouzeng 4f826b5
chore: merge
Qinyouzeng fee7de7
feat: names update
Qinyouzeng a4356e7
feat: fix trace repeat add otlpexporter and code style update
Qinyouzeng 5b2d585
feat: code style update
Qinyouzeng edd811e
chore: tests update
Qinyouzeng e8795df
chore: merge
Qinyouzeng 2f96007
feat: change value can be null
Qinyouzeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/BasicAbility/Masa.Contrib.BasicAbility.Tsc/Extensions/CallerProviderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
[assembly: InternalsVisibleTo("Masa.Contrib.BasicAbility.Tsc.Tests")] | ||
namespace Masa.Utils.Caller.Core; | ||
|
||
internal static class CallerProviderExtensions | ||
{ | ||
public static async Task<TResult> GetByBodyAsync<TResult>(this ICallerProvider caller, string url, object body) where TResult : class | ||
{ | ||
var request = new HttpRequestMessage(HttpMethod.Get, url); | ||
if (body != null) | ||
{ | ||
request.Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"); | ||
} | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (await caller.SendAsync<TResult>(request,default)) ?? default!; | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/BasicAbility/Masa.Contrib.BasicAbility.Tsc/Extensions/ServiceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
[assembly: InternalsVisibleTo("Masa.Contrib.BasicAbility.Tsc.Tests")] | ||
namespace Masa.Contrib.BasicAbility.Tsc; | ||
|
||
public static class ServiceExtensions | ||
{ | ||
private const string DEFAULT_CLIENT_NAME = "masa.contrib.basicability.tsc"; | ||
|
||
public static IServiceCollection AddTscClient(this IServiceCollection services, string tscServiceBaseUri) | ||
{ | ||
ArgumentNullException.ThrowIfNull(tscServiceBaseUri, nameof(tscServiceBaseUri)); | ||
|
||
if (services.Any(service => service.ServiceType == typeof(ITscClient))) | ||
return services; | ||
|
||
services.AddCaller(builder => | ||
{ | ||
builder.UseHttpClient(options => | ||
{ | ||
options.BaseAddress = tscServiceBaseUri; | ||
options.Name = DEFAULT_CLIENT_NAME; | ||
}); | ||
}); | ||
|
||
services.AddSingleton<ITscClient>(serviceProvider => | ||
{ | ||
var caller = serviceProvider.GetRequiredService<ICallerFactory>().CreateClient(DEFAULT_CLIENT_NAME); | ||
var pmCaching = new TscClient(caller); | ||
return pmCaching; | ||
}); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/BasicAbility/Masa.Contrib.BasicAbility.Tsc/Service/LogService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.BasicAbility.Tsc.Service; | ||
|
||
public class LogService : ILogService | ||
{ | ||
private readonly ICallerProvider _caller; | ||
internal const string AGGREGATION_URI = "/api/log/aggregation"; | ||
internal const string LATEST_URI = "/api/log/latest"; | ||
internal const string FIELD_URI = "/api/log/field"; | ||
|
||
public LogService(ICallerProvider caller) | ||
{ | ||
_caller = caller; | ||
} | ||
|
||
public async Task<IEnumerable<KeyValuePair<string, string>>> GetAggregationAsync(LogAggregationRequest query) | ||
{ | ||
return (await _caller.GetAsync<IEnumerable<KeyValuePair<string, string>>>(AGGREGATION_URI, query)) ?? default!; | ||
} | ||
|
||
public async Task<IEnumerable<string>> GetFieldsAsync() | ||
{ | ||
return (await _caller.GetAsync<IEnumerable<string>>(FIELD_URI)) ?? default!; | ||
} | ||
|
||
public async Task<object> GetLatestAsync(LogLatestRequest query) | ||
{ | ||
return (await _caller.GetAsync<object>(LATEST_URI, query)) ?? default!; | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/BasicAbility/Masa.Contrib.BasicAbility.Tsc/Service/MetricService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.BasicAbility.Tsc.Service; | ||
|
||
internal class MetricService : IMetricService | ||
{ | ||
private readonly ICallerProvider _caller; | ||
internal const string RANGEVALUES_URL = "/api/metric/range-values"; | ||
internal const string NAMES_URI = "/api/metric/names"; | ||
internal const string LABELVALUES_URI = "/api/metric/label-values"; | ||
|
||
public MetricService(ICallerProvider caller) | ||
{ | ||
_caller = caller; | ||
} | ||
|
||
public async Task<IEnumerable<string>> GetMetricNamesAsync(IEnumerable<string>? match = default) | ||
{ | ||
string param = default!; | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (match != null && match.Any(s => !string.IsNullOrEmpty(s))) | ||
{ | ||
param = string.Join(',', match.Where(s => !string.IsNullOrEmpty(s))); | ||
} | ||
return (await _caller.GetAsync<IEnumerable<string>>(NAMES_URI, new { match = param })) ?? default!; | ||
} | ||
|
||
public async Task<Dictionary<string, List<string>>> GetLabelAndValuesAsync(MetricLableValuesRequest query) | ||
{ | ||
var data = await _caller.GetByBodyAsync<Dictionary<string, Dictionary<string, List<string>>>>(LABELVALUES_URI, query); | ||
if (data == null || !data.ContainsKey(query.Match)) | ||
return default!; | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return data[query.Match]; | ||
} | ||
|
||
public async Task<string> GetMetricValuesAsync(MetricRangeValueRequest query) | ||
{ | ||
if (query.Lables != null && !string.IsNullOrEmpty(query.Match)) | ||
Qinyouzeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
query.Match = $"{query.Match}{{{string.Join(',',query.Lables)}}}"; | ||
} | ||
|
||
return (await _caller.GetByBodyAsync<string>(RANGEVALUES_URL, query)) ?? default!; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/BasicAbility/Masa.Contrib.BasicAbility.Tsc/TscClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
[assembly: InternalsVisibleTo("Masa.Contrib.BasicAbility.Tsc.Tests")] | ||
namespace Masa.Contrib.BasicAbility.Tsc; | ||
|
||
internal class TscClient : ITscClient | ||
{ | ||
public TscClient(ICallerProvider callerProvider) | ||
{ | ||
LogService = new LogService(callerProvider); | ||
MetricService = new MetricService(callerProvider); | ||
} | ||
|
||
public ILogService LogService { get; } | ||
|
||
public IMetricService MetricService { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule MASA.BuildingBlocks
updated
19 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
using System.Net.Http; | ||
using System.Text; | ||
|
||
namespace Masa.Contrib.BasicAbility.Tsc.Tests; | ||
|
||
internal class Common | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete blank lines |
||
public static HttpRequestMessage CreateMessage(string url, object body) | ||
zhenlei520 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var request = new HttpRequestMessage(HttpMethod.Get, url); | ||
if (body != null) | ||
{ | ||
request.Content = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"); | ||
} | ||
return request; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/Masa.Contrib.BasicAbility.Tsc.Test/Extensions/CallerProviderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.BasicAbility.Tsc.Tests.Extensions; | ||
|
||
[TestClass] | ||
public class CallerProviderExtensionsTests | ||
{ | ||
[TestMethod] | ||
public async Task GetByBodyAsyncTest() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method name should reflect what you want to test, it can be longer |
||
{ | ||
var callerProvider = new Mock<ICallerProvider>(); | ||
string url = "http://locahost:80/test"; | ||
var param = new { name = "name" }; | ||
var result = "ok"; | ||
callerProvider.Setup(provider => provider.SendAsync<string>(It.IsAny<HttpRequestMessage>(), default)).ReturnsAsync(result); | ||
var str = await callerProvider.Object.GetByBodyAsync<string>(url, "name"); | ||
Assert.IsNotNull(str); | ||
Assert.AreEqual(result, str); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/Masa.Contrib.BasicAbility.Tsc.Test/Masa.Contrib.BasicAbility.Tsc.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTeskSdkPackageVersion)" /> | ||
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestPackageVersion)" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestPackageVersion)" /> | ||
<PackageReference Include="coverlet.collector" Version="$(CoverletPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\BasicAbility\Masa.Contrib.BasicAbility.Tsc\Masa.Contrib.BasicAbility.Tsc.csproj" /> | ||
<ProjectReference Include="..\..\src\BuildingBlocks\MASA.BuildingBlocks\src\BasicAbility\Masa.BuildingBlocks.BasicAbility.Tsc\Masa.BuildingBlocks.BasicAbility.Tsc.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
body is not null, if body is nullable, its type is object?