Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using Microsoft.Azure.Cosmos.Core;
using Microsoft.Azure.Cosmos.Core.Utf8;
using Newtonsoft.Json;

using Microsoft.Azure.Cosmos.Core.Utf8;

/// <summary>
/// Query index utilization metrics in the Azure Cosmos database service.
/// </summary>
Expand All @@ -36,7 +36,6 @@ sealed class IndexUtilizationInfo
/// <param name="potentialSingleIndexes">The potential single indexes list</param>
/// <param name="utilizedCompositeIndexes">The potential composite indexes list</param>
/// <param name="potentialCompositeIndexes">The utilized composite indexes list</param>
[JsonConstructor]
public IndexUtilizationInfo(
IReadOnlyList<SingleIndexUtilizationEntity> utilizedSingleIndexes,
IReadOnlyList<SingleIndexUtilizationEntity> potentialSingleIndexes,
Expand Down Expand Up @@ -74,16 +73,12 @@ internal static bool TryCreateFromDelimitedBase64String(string delimitedString,
// so this class exists solely for legacy support.
try
{
string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));

result = JsonConvert.DeserializeObject<IndexUtilizationInfo>(decodedString, new JsonSerializerSettings()
{
// Allowing null values to be resilient to Json structure change
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
// Ignore parsing error encountered in desrialization
Error = (sender, parsingErrorEvent) => parsingErrorEvent.ErrorContext.Handled = true
}) ?? IndexUtilizationInfo.Empty;
string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));

// TODO - Allowing null values to be resilient to Json structure change
// TODO - Ignore parsing error encountered in desrialization
result = JsonSerializer.Deserialize(decodedString, CosmosSerializerContext.Default.IndexUtilizationInfo) ??
IndexUtilizationInfo.Empty;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace Microsoft.Azure.Cosmos.Query.Core.QueryPlan
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Routing;
using Microsoft.Azure.Cosmos.Tracing;
using Newtonsoft.Json;
using System.Text.Json;
using PartitionKeyDefinition = Documents.PartitionKeyDefinition;
using PartitionKeyInternal = Documents.Routing.PartitionKeyInternal;
using PartitionKind = Documents.PartitionKind;
using ServiceInteropWrapper = Documents.ServiceInteropWrapper;
using ServiceInteropWrapper = Documents.ServiceInteropWrapper;

internal sealed class QueryPartitionProvider : IDisposable
{
Expand Down Expand Up @@ -65,7 +65,9 @@ public QueryPartitionProvider(IDictionary<string, object> queryengineConfigurati
#endif

this.disposed = false;
this.queryengineConfiguration = JsonConvert.SerializeObject(queryengineConfiguration);
this.queryengineConfiguration = JsonSerializer.Serialize(
queryengineConfiguration,
CosmosSerializerContext.Default.DictionaryStringObject);
this.ClientDisableOptimisticDirectExecution = GetClientDisableOptimisticDirectExecution((IReadOnlyDictionary<string, object>)queryengineConfiguration);
this.serviceProvider = IntPtr.Zero;

Expand Down Expand Up @@ -94,7 +96,9 @@ public void Update(IDictionary<string, object> queryengineConfiguration)
{
lock (this.serviceProviderStateLock)
{
string newConfiguration = JsonConvert.SerializeObject(queryengineConfiguration);
string newConfiguration = JsonSerializer.Serialize(
queryengineConfiguration,
CosmosSerializerContext.Default.DictionaryStringObject);

if (!string.Equals(this.queryengineConfiguration, newConfiguration))
{
Expand Down Expand Up @@ -231,7 +235,9 @@ internal TryCatch<PartitionedQueryExecutionInfoInternal> TryGetPartitionedQueryE
uint serializedQueryExecutionInfoResultLength;

string vectorEmbeddingPolicyString = vectorEmbeddingPolicy != null ?
JsonConvert.SerializeObject(vectorEmbeddingPolicy) :
JsonSerializer.Serialize(
Comment thread
adityasa marked this conversation as resolved.
vectorEmbeddingPolicy,
CosmosSerializerContext.Default.VectorEmbeddingPolicy) :
null;

unsafe
Expand Down Expand Up @@ -314,13 +320,9 @@ internal TryCatch<PartitionedQueryExecutionInfoInternal> TryGetPartitionedQueryE
}

PartitionedQueryExecutionInfoInternal queryInfoInternal =
JsonConvert.DeserializeObject<PartitionedQueryExecutionInfoInternal>(
serializedQueryExecutionInfo,
new JsonSerializerSettings
{
DateParseHandling = DateParseHandling.None,
MaxDepth = 64, // https://github.com/advisories/GHSA-5crp-9r3c-p9vr
});
JsonSerializer.Deserialize(
serializedQueryExecutionInfo,
CosmosSerializerContext.Default.PartitionedQueryExecutionInfoInternal);

if (!this.ValidateQueryExecutionInfo(queryInfoInternal, out ArgumentException innerException))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Microsoft.Azure.Cosmos
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.Metrics;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.CrossPartition.OrderBy;
using Microsoft.Azure.Cosmos.Query.Core.QueryClient;
using Microsoft.Azure.Cosmos.Query.Core.QueryPlan;
Expand All @@ -21,46 +22,48 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Documents;

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(AccountConsistency))]
[JsonSerializable(typeof(AccountProperties))]
[JsonSerializable(typeof(AzureVMMetadata))]
[JsonSerializable(typeof(ConsistencyConfig))]
[JsonSerializable(typeof(GatewayConnectionConfig))]
[JsonSerializable(typeof(OtherConnectionConfig))]
[JsonSerializable(typeof(SqlQuerySpec))]
[JsonSerializable(typeof(SqlParameterCollection))]
[JsonSerializable(typeof(PartitionKeyDefinition))]
[JsonSerializable(typeof(IndexingPolicy))]
[JsonSerializable(typeof(GeospatialConfig))]
[JsonSerializable(typeof(UniqueKeyPolicy))]
[JsonSerializable(typeof(ConflictResolutionPolicy))]
[JsonSerializable(typeof(ClientEncryptionPolicy))]
[JsonSerializable(typeof(VectorEmbeddingPolicy))]
[JsonSerializable(typeof(Collection<AccountRegion>))]
[JsonSerializable(typeof(Collection<ComputedProperty>))]
[JsonSerializable(typeof(List<CompositeContinuationToken>))]
[JsonSerializable(typeof(Collection<string>))]
[JsonSerializable(typeof(CompositeContinuationToken))]
[JsonSerializable(typeof(FullTextPolicy))]
[JsonSerializable(typeof(ConflictResolutionPolicy))]
[JsonSerializable(typeof(ConsistencyConfig))]
[JsonSerializable(typeof(ContainerProperties))]
[JsonSerializable(typeof(PatchSpec))]
[JsonSerializable(typeof(ThroughputProperties))]
[JsonSerializable(typeof(TriggerProperties))]
[JsonSerializable(typeof(StoredProcedureProperties))]
[JsonSerializable(typeof(UserDefinedFunctionProperties))]
[JsonSerializable(typeof(CosmosQueryExecutionInfo))]
[JsonSerializable(typeof(DatabaseProperties))]
[JsonSerializable(typeof(AccountProperties))]
[JsonSerializable(typeof(Collection<AccountRegion>))]
[JsonSerializable(typeof(AccountConsistency))]
[JsonSerializable(typeof(ReplicationPolicy))]
[JsonSerializable(typeof(ReadPolicy))]
[JsonSerializable(typeof(Dictionary<string, object>))]
[JsonSerializable(typeof(Documents.Routing.Range<string>))]
[JsonSerializable(typeof(FeedResource_Address))]
[JsonSerializable(typeof(PartitionKeyRange))]
[JsonSerializable(typeof(FeedResource_PartitionKeyRange))]
[JsonSerializable(typeof(Dictionary<string, object>))]
[JsonSerializable(typeof(Collection<string>))]
[JsonSerializable(typeof(PartitionedQueryExecutionInfo))]
[JsonSerializable(typeof(FullTextPolicy))]
[JsonSerializable(typeof(GatewayConnectionConfig))]
[JsonSerializable(typeof(GeospatialConfig))]
[JsonSerializable(typeof(HybridSearchQueryInfo))]
[JsonSerializable(typeof(Documents.Routing.Range<string>))]
[JsonSerializable(typeof(QueryInfo))]
[JsonSerializable(typeof(IndexingPolicy))]
[JsonSerializable(typeof(IndexUtilizationInfo))]
[JsonSerializable(typeof(IReadOnlyList<SortOrder>))]
[JsonSerializable(typeof(CosmosQueryExecutionInfo))]
[JsonSerializable(typeof(List<CompositeContinuationToken>))]
[JsonSerializable(typeof(OtherConnectionConfig))]
[JsonSerializable(typeof(PartitionKeyDefinition))]
[JsonSerializable(typeof(PartitionKeyRange))]
[JsonSerializable(typeof(PartitionedQueryExecutionInfo))]
[JsonSerializable(typeof(PartitionedQueryExecutionInfoInternal))]
[JsonSerializable(typeof(PatchSpec))]
[JsonSerializable(typeof(QueryInfo))]
[JsonSerializable(typeof(ReadPolicy))]
[JsonSerializable(typeof(ReplicationPolicy))]
[JsonSerializable(typeof(SqlQuerySpec))]
[JsonSerializable(typeof(SqlParameterCollection))]
[JsonSerializable(typeof(StoredProcedureProperties))]
[JsonSerializable(typeof(ThroughputProperties))]
[JsonSerializable(typeof(TriggerProperties))]
[JsonSerializable(typeof(UniqueKeyPolicy))]
[JsonSerializable(typeof(UserDefinedFunctionProperties))]
[JsonSerializable(typeof(VectorEmbeddingPolicy))]
internal partial class CosmosSerializerContext : JsonSerializerContext
{
}
Expand Down