Skip to content

Commit

Permalink
Promote status codes to GA (#413)
Browse files Browse the repository at this point in the history
* Promote status codes to GA

* Update verify

* Fix tests
  • Loading branch information
einarmo authored May 8, 2024
1 parent 9ed4c63 commit 90e3673
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 794 deletions.
2 changes: 1 addition & 1 deletion Cognite.Extensions/Cognite.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.3" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="CogniteSdk" Version="3.30.0" />
<PackageReference Include="CogniteSdk" Version="3.31.0" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.4" />
Expand Down
2 changes: 0 additions & 2 deletions Cognite.Extensions/CogniteUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Com.Cognite.V1.Timeseries.Proto.Beta;
using Cognite.Extensions.Beta;

namespace Cognite.Extensions
{
Expand Down
694 changes: 0 additions & 694 deletions Cognite.Extensions/TimeSeries/Beta/DataPointExtensions.cs

This file was deleted.

14 changes: 12 additions & 2 deletions Cognite.Extensions/TimeSeries/DataPointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,24 @@ public static DataPointInsertionRequest ToInsertRequest(this IDictionary<Identit
.Select(dp => new StringDatapoint
{
Timestamp = dp.Timestamp,
Value = dp.StringValue
Value = dp.StringValue,
NullValue = dp.StringValue is null,
Status = new Status
{
Code = (long)dp.Status.Code
}
});
var numericPoints = kvp.Value
.Where(dp => !dp.IsString && dp.Status.IsGood)
.Select(dp => new NumericDatapoint
{
Timestamp = dp.Timestamp,
Value = dp.NumericValue!.Value
Value = dp.NumericValue!.Value,
NullValue = dp.NumericValue is null,
Status = new Status
{
Code = (long)dp.Status.Code
}
});
if (stringPoints.Any())
{
Expand Down
5 changes: 3 additions & 2 deletions Cognite.Extensions/TimeSeries/DataPointSanitation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public static Datapoint Sanitize(this Datapoint point, double? nanReplacement)
{
if (point.IsString)
{
if (point.StringValue == null || point.StringValue.Length > CogniteUtils.StringLengthMax)
if (point.StringValue == null && point.Status.IsGood
|| (point.StringValue?.Length ?? 0) > CogniteUtils.StringLengthMax)
{
return ResourceType.DataPointValue;
}
}
else
else if (point.Status.IsGood)
{
double value = point.NumericValue!.Value;
if (double.IsNaN(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Text;

namespace Cognite.Extensions.Beta
namespace Cognite.Extensions
{
// NOTE: This entire section is largely taken from the time series backend,
// it more or less replicates the behavior of the API when it comes to parsing and handling status codes.
Expand Down Expand Up @@ -239,11 +239,6 @@ public static StatusCode Parse(string symbol)
{
return "Calculated and Interpolated flags are mutually exclusive";
}

if (infoBits == 0)
{
return "When info type is 01, info bits must not be 0";
}
}
else if (infoBits != 0)
{
Expand Down
4 changes: 2 additions & 2 deletions ExtractorUtils.Test/integration/RawHighAvailabilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public RawHighAvailabilityTest(ITestOutputHelper output)
}

[Fact(Timeout = 30000)]
public async void TestExtractorManagerRun()
public async Task TestExtractorManagerRun()
{
// Creating configs for two different extractors.
string configPath_0 = SetupConfig(index: 0);
Expand Down Expand Up @@ -101,7 +101,7 @@ public async void TestExtractorManagerRun()
}

[Fact(Timeout = 45000)]
public async void TestRestartExtractor()
public async Task TestRestartExtractor()
{
// Creating config for two extractors.
string configPath_0 = SetupConfig(index: 2);
Expand Down
4 changes: 2 additions & 2 deletions ExtractorUtils.Test/integration/RedisHighAvailabilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RedisHighAvailabilityTest(ITestOutputHelper output)
}

[Fact(Timeout = 30000)]
public async void TestRedisExtractorManagerRun()
public async Task TestRedisExtractorManagerRun()
{
Assert.True(_redis.IsConnected);

Expand Down Expand Up @@ -58,7 +58,7 @@ public async void TestRedisExtractorManagerRun()
}

[Fact(Timeout = 45000)]
public async void TestRedisRestartExtractor()
public async Task TestRedisRestartExtractor()
{
Assert.True(_redis.IsConnected);

Expand Down
5 changes: 2 additions & 3 deletions ExtractorUtils.Test/unit/BinaryBufferTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Cognite.Extensions;
using Cognite.Extensions.Beta;
using Cognite.Extractor.Utils;
using CogniteSdk;
using System;
Expand Down Expand Up @@ -30,8 +29,8 @@ public async Task TestBinaryBufferData()
{ Identity.Create(123), new [] {new Datapoint(t1, "321"), new Datapoint(t2, 321.321) } },
{ Identity.Create("empty"), Array.Empty<Datapoint>() },
{ Identity.Create("status"), new[] {
new Datapoint(t1, 123.123, StatusCode.FromCategory(StatusCodeCategory.GoodCascade)),
new Datapoint(t2, 321.321, StatusCode.FromCategory(StatusCodeCategory.BadNoCommunication))
new Datapoint(t1, 123.123, Cognite.Extensions.StatusCode.FromCategory(StatusCodeCategory.GoodCascade)),
new Datapoint(t2, 321.321, Cognite.Extensions.StatusCode.FromCategory(StatusCodeCategory.BadNoCommunication))
} }
};
var dps2 = new Dictionary<Identity, IEnumerable<Datapoint>>() {
Expand Down
2 changes: 1 addition & 1 deletion ExtractorUtils.Test/unit/StatusCodeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Cognite.Extensions.Beta;
using Cognite.Extensions;
using Xunit;

namespace ExtractorUtils.Test.Unit
Expand Down
78 changes: 0 additions & 78 deletions ExtractorUtils/Cognite/CogniteDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,46 +413,6 @@ public async Task<CogniteResult<DataPointInsertError>> InsertDataPointsAsync(
token).ConfigureAwait(false);
}

/// <summary>
/// BETA: Insert the provided data points into CDF. The data points are chunked
/// according to <see cref="CogniteConfig.CdfChunking"/> and trimmed according to the
/// <see href="https://docs.cognite.com/api/v1/#operation/postMultiTimeSeriesDatapoints">CDF limits</see>.
/// The <paramref name="points"/> dictionary keys are time series identities (Id or ExternalId) and the values are numeric or string data points
///
/// On error, the offending timeseries/datapoints can optionally be removed.
///
/// This version includes beta support for status codes.
/// </summary>
/// <param name="points">Data points</param>
/// <param name="sanitationMode"></param>
/// <param name="retryMode"></param>
/// <param name="token">Cancellation token</param>
public async Task<CogniteResult<DataPointInsertError>> BetaInsertDataPointsAsync(
IDictionary<Identity, IEnumerable<Datapoint>>? points,
SanitationMode sanitationMode,
RetryMode retryMode,
CancellationToken token)
{
if (points == null || !points.Any()) return new CogniteResult<DataPointInsertError>(null);

_logger.LogDebug("Uploading {Number} data points to CDF for {NumberTs} time series",
points.Values.Select(dp => dp.Count()).Sum(),
points.Keys.Count);
return await Extensions.Beta.DataPointExtensions.InsertAsync(
_client,
points,
_config.CdfChunking.DataPointTimeSeries,
_config.CdfChunking.DataPoints,
_config.CdfThrottling.DataPoints,
_config.CdfChunking.TimeSeries,
_config.CdfThrottling.TimeSeries,
_config.CdfChunking.DataPointsGzipLimit,
sanitationMode,
retryMode,
_config.NanReplacement,
token).ConfigureAwait(false);
}

/// <summary>
/// Insert datapoints to timeseries. Insertions are chunked and cleaned according to configuration,
/// and can optionally handle errors. If any timeseries missing from the result and inserted by externalId,
Expand Down Expand Up @@ -489,44 +449,6 @@ public async Task<CogniteResult<DataPointInsertError>> BetaInsertDataPointsAsync
token).ConfigureAwait(false);
}

/// <summary>
/// BETA: Insert datapoints to timeseries. Insertions are chunked and cleaned according to configuration,
/// and can optionally handle errors. If any timeseries missing from the result and inserted by externalId,
/// they are created before the points are inserted again.
///
/// This version includes beta support for status codes.
/// </summary>
/// <param name="points">Datapoints to insert</param>
/// <param name="sanitationMode">How to sanitize datapoints</param>
/// <param name="retryMode">How to handle retries</param>
/// <param name="dataSetId">Optional data set id</param>
/// <param name="token">Cancellation token</param>
/// <returns>Results with a list of errors. If TimeSeriesResult is null, no timeseries were attempted created.</returns>
public async Task<(CogniteResult<DataPointInsertError> DataPointResult, CogniteResult<TimeSeries, TimeSeriesCreate>? TimeSeriesResult)> BetaInsertDataPointsCreateMissingAsync(
IDictionary<Identity, IEnumerable<Datapoint>>? points,
SanitationMode sanitationMode,
RetryMode retryMode,
long? dataSetId,
CancellationToken token)
{
if (points == null || !points.Any()) return (new CogniteResult<DataPointInsertError>(null), null);

return await Extensions.Beta.DataPointExtensions.InsertAsyncCreateMissing(
_client,
points,
_config.CdfChunking.DataPointTimeSeries,
_config.CdfChunking.DataPoints,
_config.CdfThrottling.DataPoints,
_config.CdfChunking.TimeSeries,
_config.CdfThrottling.TimeSeries,
_config.CdfChunking.DataPointsGzipLimit,
sanitationMode,
retryMode,
_config.NanReplacement,
dataSetId,
token).ConfigureAwait(false);
}

/// <summary>
/// Deletes ranges of data points in CDF. The <paramref name="ranges"/> parameter contains the first (inclusive)
/// and last (inclusive) timestamps for the range. After the delete request is sent to CDF, attempt to confirm that
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.22.2
1.23.0

0 comments on commit 90e3673

Please sign in to comment.