Skip to content

Commit

Permalink
Merge pull request #6 from JasonMing/features/header_access
Browse files Browse the repository at this point in the history
支持读取 x-log-* 响应头内容
  • Loading branch information
tangkai1719 authored Aug 30, 2018
2 parents f6c424c + dd402b5 commit aed4471
Show file tree
Hide file tree
Showing 13 changed files with 532 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Aliyun.Api.LogService.Examples/ApiUsage/PullLogsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Linq;
using System.Threading.Tasks;
using Aliyun.Api.LogService.Domain.Log;
using Aliyun.Api.LogService.Infrastructure.Protocol.Http;

namespace Aliyun.Api.LogService.Examples.ApiUsage
{
Expand All @@ -51,6 +52,9 @@ public static async Task<IEnumerable<LogInfo>> PullLogs(ILogServiceClient client
// 在指定分片(shard)上从游标(cursor)开始位置获取100条日志
var response = await client.PullLogsAsync(LogStoreName, shardId, cursor, 100);
var result = response.EnsureSuccess().Result;

// 获取Header上的下一条游标(cursor)位置
var nextCursor = response.GetLogCursor();

return result.LogGroups
.SelectMany(x => x.Logs);
Expand Down
52 changes: 46 additions & 6 deletions Aliyun.Api.LogService.Tests/DefaultLogServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ public async Task TestPostLogStoreLogs()
Source = "UnitTest",
LogTags = new Dictionary<String, String>
{
{"Tag1", "Value1"},
{"Tag2", "Value2"}
{"Tag1", null},
{"Tag2", String.Empty},
{"Tag3", "far"}
},
Logs = new List<LogInfo>
{
Expand All @@ -373,7 +374,8 @@ public async Task TestPostLogStoreLogs()
Time = DateTimeOffset.Now,
Contents = new Dictionary<String, String>
{
{"foo", "bar"},
{"foo", null},
{"bar", String.Empty},
{"far", "baz"}
}
}
Expand All @@ -394,8 +396,9 @@ public async Task TestPostLogStoreLogsWithHashKey()
Source = "UnitTest",
LogTags = new Dictionary<String, String>
{
{"Tag1", "Value1"},
{"Tag2", "Value2"}
{"Tag1", null},
{"Tag2", String.Empty},
{"Tag3", "Value2"}
},
Logs = new List<LogInfo>
{
Expand All @@ -404,7 +407,8 @@ public async Task TestPostLogStoreLogsWithHashKey()
Time = DateTimeOffset.Now,
Contents = new Dictionary<String, String>
{
{"foo", "bar"},
{"foo", null},
{"bar", String.Empty},
{"far", "baz"}
}
}
Expand All @@ -421,6 +425,13 @@ public async Task TestPullLogs()
var response = await this.context.Client.PullLogsAsync(this.context.LogStoreName, this.context.WholeShardId, this.context.Cursor, 10);
this.PrintResponse(response);
Assert.True(response.IsSuccess);

this.output.WriteLine("================================");
this.output.WriteLine("Known headers:");
this.output.WriteLine($"{LogHeaders.Count}={response.GetLogCount()}");
this.output.WriteLine($"{LogHeaders.BodyRawSize}={response.GetLogBodyRawSize()}");
this.output.WriteLine($"{LogHeaders.CompressType}={response.GetLogCompressType()}");
this.output.WriteLine($"{LogHeaders.Cursor}={response.GetLogCursor()}");
}

[Fact, TestPriority(nameof(TestPostLogStoreLogs))]
Expand Down Expand Up @@ -449,6 +460,18 @@ async Task<IResponse<GetLogsResult>> Run()

this.PrintResponse(response);
Assert.True(response.IsSuccess);

this.output.WriteLine("================================");
this.output.WriteLine("Known headers:");
this.output.WriteLine($"{LogHeaders.Count}={response.GetLogCount()}");
this.output.WriteLine($"{LogHeaders.ElapsedMillisecond}={response.GetLogElapsedMillisecond()}");
this.output.WriteLine($"{LogHeaders.ProcessedRows}={response.GetLogProcessedRows()}");
this.output.WriteLine($"{LogHeaders.Progress}={response.GetLogProgress()}");
this.output.WriteLine($"{LogHeaders.HasSql}={response.GetLogHasSql()}");
this.output.WriteLine($"{LogHeaders.QueryInfo}={response.GetLogQueryInfo()}");
this.output.WriteLine($"{LogHeaders.QueryInfo}(Dynamic)={response.GetLogQueryInfoAsDynamic()}");
this.output.WriteLine($"{LogHeaders.AggQuery}={response.GetLogAggQuery()}");
this.output.WriteLine($"{LogHeaders.WhereQuery}={response.GetLogWhereQuery()}");
}

[Fact, TestPriority(nameof(TestGetLogStore), nameof(TestPostLogStoreLogs))]
Expand All @@ -458,6 +481,18 @@ public async Task TestGetProjectLogs()
$"select count(*) from {this.context.LogStoreName}");
this.PrintResponse(response, true);
Assert.True(response.IsSuccess);

this.output.WriteLine("================================");
this.output.WriteLine("Known headers:");
this.output.WriteLine($"{LogHeaders.Count}={response.GetLogCount()}");
this.output.WriteLine($"{LogHeaders.ElapsedMillisecond}={response.GetLogElapsedMillisecond()}");
this.output.WriteLine($"{LogHeaders.ProcessedRows}={response.GetLogProcessedRows()}");
this.output.WriteLine($"{LogHeaders.Progress}={response.GetLogProgress()}");
this.output.WriteLine($"{LogHeaders.HasSql}={response.GetLogHasSql()}");
this.output.WriteLine($"{LogHeaders.QueryInfo}={response.GetLogQueryInfo()}");
this.output.WriteLine($"{LogHeaders.QueryInfo}(Dynamic)={response.GetLogQueryInfoAsDynamic()}");
this.output.WriteLine($"{LogHeaders.AggQuery}={response.GetLogAggQuery()}");
this.output.WriteLine($"{LogHeaders.WhereQuery}={response.GetLogWhereQuery()}");
}

[Fact, TestPriority(nameof(TestGetLogStore), nameof(TestPostLogStoreLogs))]
Expand All @@ -469,6 +504,11 @@ public async Task TestGetHistograms()
DateTimeOffset.UtcNow);
this.PrintResponse(response);
Assert.True(response.IsSuccess);

this.output.WriteLine("================================");
this.output.WriteLine("Known headers:");
this.output.WriteLine($"{LogHeaders.Count}={response.GetLogCount()}");
this.output.WriteLine($"{LogHeaders.Progress}={response.GetLogProgress()}");
}

#endregion Log
Expand Down
2 changes: 1 addition & 1 deletion Aliyun.Api.LogService/Aliyun.Api.LogService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>Aliyun </PackageTags>
<Title>Aliyun LogService .Net Core SDK</Title>
<PackOnBuild>true</PackOnBuild>
<PackageVersion>1.0.1</PackageVersion>
<PackageVersion>1.1.0</PackageVersion>
<Description>Aliyun LogService SDK for .NET Core.</Description>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(OS)' == 'Release|Windows_NT' ">
Expand Down
26 changes: 26 additions & 0 deletions Aliyun.Api.LogService/Domain/LogServiceException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//
// LogServiceClientBuilders.cs
//
// Author:
// MiNG <[email protected]>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Aliyun.Api.LogService.Infrastructure.Protocol;

Expand Down
26 changes: 26 additions & 0 deletions Aliyun.Api.LogService/Domain/Project/ProjectScopedRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//
// LogServiceClientBuilders.cs
//
// Author:
// MiNG <[email protected]>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Newtonsoft.Json;

Expand Down
26 changes: 26 additions & 0 deletions Aliyun.Api.LogService/Infrastructure/Authentication/Credential.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//
// LogServiceClientBuilders.cs
//
// Author:
// MiNG <[email protected]>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace Aliyun.Api.LogService.Infrastructure.Authentication
Expand Down
Loading

0 comments on commit aed4471

Please sign in to comment.