Skip to content

Commit b7a8d0c

Browse files
authored
Migrate Scale Metrics to Azure.Data.Tables with support for Identity-based connections (#10436)
1 parent 0b6ba8b commit b7a8d0c

16 files changed

+547
-327
lines changed

release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
- Resolved thread safety issue in the `GrpcWorkerChannel.LoadResponse` method. (#10352)
1717
- Worker termination path updated with sanitized logging (#10397)
1818
- Avoid redundant DiagnosticEvents error message (#10395)
19+
- Migrated Scale Metrics to use `Azure.Data.Tables` SDK (#10276)
20+
- Added support for Identity-based connections

src/WebJobs.Script.WebHost/Scale/TableEntityConverter.cs

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.Azure.Cosmos.Table;
6+
using Azure;
7+
using Azure.Data.Tables;
78
using Newtonsoft.Json.Linq;
89

910
namespace Microsoft.Azure.WebJobs.Script.WebHost.Scale
1011
{
1112
/// <summary>
12-
/// Class providing methods to convert between DynamicTableEntity and custom pocos
13+
/// Class providing methods to convert between <see cref="TableEntity"/> and custom pocos.
1314
/// </summary>
1415
internal static class TableEntityConverter
1516
{
16-
public static DynamicTableEntity ToEntity(object o,
17+
public static TableEntity ToEntity(object o,
1718
string partitionKey = null,
1819
string rowKey = null,
1920
DateTimeOffset? timeStamp = null,
2021
string etag = null)
2122
{
22-
var entity = new DynamicTableEntity
23+
var entity = new TableEntity
2324
{
2425
RowKey = rowKey,
25-
PartitionKey = partitionKey,
26-
Properties = new Dictionary<string, EntityProperty>()
26+
PartitionKey = partitionKey
2727
};
2828

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

3434
if (!string.IsNullOrWhiteSpace(etag))
3535
{
36-
entity.ETag = etag;
36+
entity.ETag = new ETag(etag);
3737
}
3838

3939
var jo = JObject.FromObject(o);
4040
foreach (var prop in jo.Properties())
4141
{
42-
if (TryGetEntityProperty(prop, out EntityProperty entityProperty))
42+
if (TryGetEntityProperty(prop, out object value))
4343
{
44-
entity.Properties.Add(prop.Name, entityProperty);
44+
entity.Add(prop.Name, value);
4545
}
4646
}
4747

4848
return entity;
4949
}
5050

51-
public static object ToObject(Type type, DynamicTableEntity entity)
52-
{
53-
return ToObject(type, entity.Properties);
54-
}
55-
56-
public static TOutput ToObject<TOutput>(IDictionary<string, EntityProperty> properties)
51+
public static TOutput ToObject<TOutput>(IDictionary<string, object> properties)
5752
{
5853
return (TOutput)ToObject(typeof(TOutput), properties);
5954
}
6055

61-
public static object ToObject(Type type, IDictionary<string, EntityProperty> properties)
56+
public static object ToObject(Type type, IDictionary<string, object> properties)
6257
{
6358
var jo = new JObject();
6459
foreach (var pair in properties)
6560
{
66-
ApplyProperty(jo, pair.Key, pair.Value);
61+
jo.Add(pair.Key, new JValue(pair.Value));
6762
}
6863
return jo.ToObject(type);
6964
}
7065

71-
public static bool TryGetEntityProperty(JProperty property, out EntityProperty entityProperty)
66+
public static bool TryGetEntityProperty(JProperty property, out object entityProperty)
7267
{
7368
entityProperty = null;
7469
var value = property.Value;
7570

7671
switch (value.Type)
7772
{
7873
case JTokenType.Bytes:
79-
entityProperty = new EntityProperty(value.ToObject<byte[]>());
74+
entityProperty = value.ToObject<byte[]>();
8075
return true;
8176
case JTokenType.Boolean:
82-
entityProperty = new EntityProperty(value.ToObject<bool>());
77+
entityProperty = value.ToObject<bool>();
8378
return true;
8479
case JTokenType.Date:
85-
entityProperty = new EntityProperty(value.ToObject<DateTime>());
80+
entityProperty = value.ToObject<DateTime>();
8681
return true;
8782
case JTokenType.Float:
88-
entityProperty = new EntityProperty(value.ToObject<double>());
83+
entityProperty = value.ToObject<double>();
8984
return true;
9085
case JTokenType.Guid:
91-
entityProperty = new EntityProperty(value.ToObject<Guid>());
86+
entityProperty = value.ToObject<Guid>();
9287
return true;
9388
case JTokenType.Integer:
9489
// to handle both ints and longs, we normalize integer values
9590
// to type long
96-
entityProperty = new EntityProperty(value.ToObject<long>());
91+
entityProperty = value.ToObject<long>();
9792
return true;
9893
case JTokenType.String:
9994
case JTokenType.TimeSpan:
100-
entityProperty = new EntityProperty(value.ToObject<string>());
95+
entityProperty = value.ToObject<string>();
10196
return true;
10297
default:
10398
return false;
10499
}
105100
}
106-
107-
public static void ApplyProperty(JObject jo, string name, EntityProperty entityProperty)
108-
{
109-
switch (entityProperty.PropertyType)
110-
{
111-
case EdmType.Binary:
112-
jo.Add(name, new JValue(entityProperty.BinaryValue));
113-
return;
114-
case EdmType.Boolean:
115-
jo.Add(name, new JValue(entityProperty.BooleanValue));
116-
return;
117-
case EdmType.DateTime:
118-
jo.Add(name, new JValue(entityProperty.DateTime));
119-
return;
120-
case EdmType.Double:
121-
jo.Add(name, new JValue(entityProperty.DoubleValue));
122-
return;
123-
case EdmType.Guid:
124-
jo.Add(name, new JValue(entityProperty.GuidValue));
125-
return;
126-
case EdmType.Int32:
127-
jo.Add(name, new JValue(entityProperty.Int32Value));
128-
return;
129-
case EdmType.Int64:
130-
jo.Add(name, new JValue(entityProperty.Int64Value));
131-
return;
132-
case EdmType.String:
133-
jo.Add(name, new JValue(entityProperty.StringValue));
134-
return;
135-
default:
136-
return;
137-
}
138-
}
139101
}
140-
}
102+
}

0 commit comments

Comments
 (0)