Skip to content

Commit

Permalink
Merge pull request #609 from aws-powertools/develop
Browse files Browse the repository at this point in the history
chore: Sync Main with Develop for release 1.11
  • Loading branch information
hjgraca authored Jul 9, 2024
2 parents 1bac3a9 + 33546b4 commit e2bfcb3
Show file tree
Hide file tree
Showing 38 changed files with 601 additions and 808 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET 6.0 & 8.0
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # 4.0.0
with:
Expand All @@ -32,10 +32,9 @@ jobs:
- name: Test & Code Coverage
run: dotnet test --collect:"XPlat Code Coverage" --results-directory ./codecov --verbosity normal
- name: Codecov
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # 4.3.1
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # 4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: false
name: codecov-lambda-powertools-dotnet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
environment: Docs
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Set up Python
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
environment: Docs
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET 6.0
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label_pr_on_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Label PR based on title"
uses: actions/github-script@v6
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on_label_added.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
# Maintenance: Persist state per PR as an artifact to avoid spam on label add
- name: "Suggest split large Pull Request"
uses: actions/github-script@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on_merged_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
if: needs.get_pr_details.outputs.prIsMerged == 'true'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Label PR related issue for release"
uses: actions/github-script@v6
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on_opened_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
needs: get_pr_details
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Ensure related issue is present"
uses: actions/github-script@v6
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/record_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Extract PR details"
uses: actions/github-script@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_export_pr_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
prIsMerged: ${{ steps.prIsMerged.outputs.prIsMerged }}
steps:
- name: Checkout repository # in case caller workflow doesn't checkout thus failing with file not found
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Download previously saved PR"
uses: actions/github-script@v6
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_publish_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository # reusable workflows start clean, so we need to checkout again
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Git client setup and refresh tip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable_publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
environment: Docs
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Install poetry
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
runs-on: macos-latest
environment: Docs
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Configure and build api docs generator
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/secure_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Ensure 3rd party workflows have SHA pinned
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@6ca5574367befbc9efdb2fa25978084159c5902d # v1.3.0
with:
Expand Down
1 change: 1 addition & 0 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
* Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)
* Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency
* Context manager to create a one off metric with a different dimension
* Ahead-of-Time compilation to native code support [AOT](https://docs.aws.amazon.com/lambda/latest/dg/dotnet-native-aot.html) from version 1.7.0

<br />

Expand Down
2 changes: 1 addition & 1 deletion examples/Metrics/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.1" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.2" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.1" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.2" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.4.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*
* http://aws.amazon.com/apache2.0
*
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
Expand All @@ -15,6 +15,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand All @@ -32,19 +33,19 @@ public class UniversalWrapperAspect
/// <summary>
/// The delegate cache
/// </summary>
private static readonly Dictionary<MethodBase, Handler> _delegateCache = new();
private static readonly Dictionary<MethodBase, Handler> DelegateCache = new();

/// <summary>
/// The asynchronous generic handler
/// </summary>
private static readonly MethodInfo _asyncGenericHandler =
private static readonly MethodInfo AsyncGenericHandler =
typeof(UniversalWrapperAttribute).GetMethod(nameof(UniversalWrapperAttribute.WrapAsync),
BindingFlags.NonPublic | BindingFlags.Instance);

/// <summary>
/// The synchronize generic handler
/// </summary>
private static readonly MethodInfo _syncGenericHandler =
private static readonly MethodInfo SyncGenericHandler =
typeof(UniversalWrapperAttribute).GetMethod(nameof(UniversalWrapperAttribute.WrapSync),
BindingFlags.NonPublic | BindingFlags.Instance);

Expand Down Expand Up @@ -94,6 +95,7 @@ public object Handle(
/// <param name="returnType">Type of the return.</param>
/// <param name="wrappers">The wrappers.</param>
/// <returns>Handler.</returns>
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "<Pending>")]
private static Handler CreateMethodHandler(Type returnType, IEnumerable<UniversalWrapperAttribute> wrappers)
{
var targetParam = Expression.Parameter(typeof(Func<object[], object>), "orig");
Expand All @@ -107,13 +109,13 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
? returnType.GenericTypeArguments[0]
: Type.GetType("System.Threading.Tasks.VoidTaskResult");
returnType = typeof(Task<>).MakeGenericType(taskType);
wrapperMethod = _asyncGenericHandler.MakeGenericMethod(taskType);
wrapperMethod = AsyncGenericHandler.MakeGenericMethod(taskType);
}
else
{
if (returnType == typeof(void))
returnType = typeof(object);
wrapperMethod = _syncGenericHandler.MakeGenericMethod(returnType);
wrapperMethod = SyncGenericHandler.MakeGenericMethod(returnType);
}

var converArgs = Expression.Parameter(typeof(object[]), "args");
Expand All @@ -128,9 +130,9 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
argsParam);
}

var orig_args = Expression.Parameter(typeof(object[]), "orig_args");
var handler = Expression.Lambda<Handler>(Expression.Convert(Expression.Invoke(next, orig_args), typeof(object)),
targetParam, orig_args, eventArgsParam);
var origArgs = Expression.Parameter(typeof(object[]), "orig_args");
var handler = Expression.Lambda<Handler>(Expression.Convert(Expression.Invoke(next, origArgs), typeof(object)),
targetParam, origArgs, eventArgsParam);

var handlerCompiled = handler.Compile();

Expand All @@ -147,14 +149,14 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
private static Handler GetMethodHandler(MethodBase method, Type returnType,
IEnumerable<UniversalWrapperAttribute> wrappers)
{
if (!_delegateCache.TryGetValue(method, out var handler))
lock (method)
{
if (!_delegateCache.TryGetValue(method, out handler))
_delegateCache[method] = handler = CreateMethodHandler(returnType, wrappers);
}

return handler;
lock (method)
{
if (!DelegateCache.TryGetValue(method, out var handler))
if (!DelegateCache.TryGetValue(method, out handler))
DelegateCache[method] = handler = CreateMethodHandler(returnType, wrappers);

return handler;
}
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions libraries/src/AWS.Lambda.Powertools.Common/Core/ISystemWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

using System.IO;

namespace AWS.Lambda.Powertools.Common;

/// <summary>
Expand Down Expand Up @@ -57,4 +59,15 @@ public interface ISystemWrapper
/// </summary>
/// <param name="type"></param>
void SetExecutionEnvironment<T>(T type);

/// <summary>
/// Sets console output
/// Useful for testing and checking the console output
/// <code>
/// var consoleOut = new StringWriter();
/// SystemWrapper.Instance.SetOut(consoleOut);
/// </code>
/// </summary>
/// <param name="writeTo">The TextWriter instance where to write to</param>
void SetOut(TextWriter writeTo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void SetExecutionEnvironment<T>(T type)
SetEnvironmentVariable(envName, envValue.ToString());
}

/// <inheritdoc />
public void SetOut(TextWriter writeTo)
{
Console.SetOut(writeTo);
}

/// <summary>
/// Parsing the name to conform with the required naming convention for the UserAgent header (PTFeature/Name/Version)
/// Fallback to Assembly Name on exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<Folder Include="Serializer\" />
</ItemGroup>

</Project>
Loading

0 comments on commit e2bfcb3

Please sign in to comment.