Skip to content

Commit

Permalink
Merge branch 'dev' into shkr/handle_dotnet_worker_channel
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyju authored Aug 28, 2024
2 parents 703d318 + ff0dea7 commit 1bd8f81
Show file tree
Hide file tree
Showing 18 changed files with 567 additions and 333 deletions.
9 changes: 5 additions & 4 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
<!-- Please add your release notes in the following format:
- My change description (#PR)
-->
- Update Java Worker Version to [2.17.0](https://github.com/Azure/azure-functions-java-worker/releases/tag/2.17.0)
- Update application insights agent version to 3.5.4
- Includes fixes from 2.16.0
- Update Python Worker Version to [4.31.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.31.0)
- Update Java Worker Version to [2.16.0](https://github.com/Azure/azure-functions-java-worker/releases/tag/2.16.0):
- Fix thread context classloader for middleware chain
- Upgraded the following package versions (#10325):
- `Azure.Security.KeyVault.Secrets` updated to 4.6.0
- `System.Format.Asn1` updated to 6.0.1
- Update Python Worker Version to [4.30.3](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.30.3)
- Update PowerShell 7.2 worker to [4.0.4020](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.4020)
- Update PowerShell 7.4 worker to [4.0.4021](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.4021)
- Updated dotnet-isolated worker to [1.0.11](https://github.com/Azure/azure-functions-dotnet-worker/pull/2653) (#10379)
- Update Java Worker Version to [2.15.0](https://github.com/Azure/azure-functions-java-worker/releases/tag/2.15.0)
- Update grpc-protobuf to 1.64.0 and application insights agent version to 3.5.2
- Resolved thread safety issue in the `GrpcWorkerChannel.LoadResponse` method. (#10352)
- Worker termination path updated with sanitized logging (#10367)
- Avoid redundant DiagnosticEvents error message (#10395)
- Added logic to shim older versions of the .NET Worker JsonFunctionProvider to ensure backwards compatibility (#10410)
- Added fallback behavior when FUNCTIONS_WORKER_RUNTIME does not match with metadata from deployed app payload.
- Migrated Scale Metrics to use `Azure.Data.Tables` SDK (#10276)
- Added support for Identity-based connections
14 changes: 14 additions & 0 deletions src/WebJobs.Script.Grpc/Server/RetryProxyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -41,6 +42,19 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

await Task.Delay(currentDelay, cancellationToken);
}
catch (Exception ex)
{
if (attemptCount == _maxRetries)
{
_logger.LogWarning("Reached the maximum retry count for worker request proxying. Error: {exception}", ex);
}
else
{
_logger.LogWarning($"Unsupported exception type in {nameof(RetryProxyHandler)}. Request will not be retried. Exception: {{exception}}", ex);
}

throw;
}
}

// This should never be reached.
Expand Down
78 changes: 20 additions & 58 deletions src/WebJobs.Script.WebHost/Scale/TableEntityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

using System;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.Table;
using Azure;
using Azure.Data.Tables;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.WebJobs.Script.WebHost.Scale
{
/// <summary>
/// Class providing methods to convert between DynamicTableEntity and custom pocos
/// Class providing methods to convert between <see cref="TableEntity"/> and custom pocos.
/// </summary>
internal static class TableEntityConverter
{
public static DynamicTableEntity ToEntity(object o,
public static TableEntity ToEntity(object o,
string partitionKey = null,
string rowKey = null,
DateTimeOffset? timeStamp = null,
string etag = null)
{
var entity = new DynamicTableEntity
var entity = new TableEntity
{
RowKey = rowKey,
PartitionKey = partitionKey,
Properties = new Dictionary<string, EntityProperty>()
PartitionKey = partitionKey
};

if (timeStamp.HasValue)
Expand All @@ -33,108 +33,70 @@ public static DynamicTableEntity ToEntity(object o,

if (!string.IsNullOrWhiteSpace(etag))
{
entity.ETag = etag;
entity.ETag = new ETag(etag);
}

var jo = JObject.FromObject(o);
foreach (var prop in jo.Properties())
{
if (TryGetEntityProperty(prop, out EntityProperty entityProperty))
if (TryGetEntityProperty(prop, out object value))
{
entity.Properties.Add(prop.Name, entityProperty);
entity.Add(prop.Name, value);
}
}

return entity;
}

public static object ToObject(Type type, DynamicTableEntity entity)
{
return ToObject(type, entity.Properties);
}

public static TOutput ToObject<TOutput>(IDictionary<string, EntityProperty> properties)
public static TOutput ToObject<TOutput>(IDictionary<string, object> properties)
{
return (TOutput)ToObject(typeof(TOutput), properties);
}

public static object ToObject(Type type, IDictionary<string, EntityProperty> properties)
public static object ToObject(Type type, IDictionary<string, object> properties)
{
var jo = new JObject();
foreach (var pair in properties)
{
ApplyProperty(jo, pair.Key, pair.Value);
jo.Add(pair.Key, new JValue(pair.Value));
}
return jo.ToObject(type);
}

public static bool TryGetEntityProperty(JProperty property, out EntityProperty entityProperty)
public static bool TryGetEntityProperty(JProperty property, out object entityProperty)
{
entityProperty = null;
var value = property.Value;

switch (value.Type)
{
case JTokenType.Bytes:
entityProperty = new EntityProperty(value.ToObject<byte[]>());
entityProperty = value.ToObject<byte[]>();
return true;
case JTokenType.Boolean:
entityProperty = new EntityProperty(value.ToObject<bool>());
entityProperty = value.ToObject<bool>();
return true;
case JTokenType.Date:
entityProperty = new EntityProperty(value.ToObject<DateTime>());
entityProperty = value.ToObject<DateTime>();
return true;
case JTokenType.Float:
entityProperty = new EntityProperty(value.ToObject<double>());
entityProperty = value.ToObject<double>();
return true;
case JTokenType.Guid:
entityProperty = new EntityProperty(value.ToObject<Guid>());
entityProperty = value.ToObject<Guid>();
return true;
case JTokenType.Integer:
// to handle both ints and longs, we normalize integer values
// to type long
entityProperty = new EntityProperty(value.ToObject<long>());
entityProperty = value.ToObject<long>();
return true;
case JTokenType.String:
case JTokenType.TimeSpan:
entityProperty = new EntityProperty(value.ToObject<string>());
entityProperty = value.ToObject<string>();
return true;
default:
return false;
}
}

public static void ApplyProperty(JObject jo, string name, EntityProperty entityProperty)
{
switch (entityProperty.PropertyType)
{
case EdmType.Binary:
jo.Add(name, new JValue(entityProperty.BinaryValue));
return;
case EdmType.Boolean:
jo.Add(name, new JValue(entityProperty.BooleanValue));
return;
case EdmType.DateTime:
jo.Add(name, new JValue(entityProperty.DateTime));
return;
case EdmType.Double:
jo.Add(name, new JValue(entityProperty.DoubleValue));
return;
case EdmType.Guid:
jo.Add(name, new JValue(entityProperty.GuidValue));
return;
case EdmType.Int32:
jo.Add(name, new JValue(entityProperty.Int32Value));
return;
case EdmType.Int64:
jo.Add(name, new JValue(entityProperty.Int64Value));
return;
case EdmType.String:
jo.Add(name, new JValue(entityProperty.StringValue));
return;
default:
return;
}
}
}
}
Loading

0 comments on commit 1bd8f81

Please sign in to comment.