Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Industrial log analytics #400

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ jobs:
- name: Test
run: ./test.sh
env:
TEST_HOST_WRITE: "https://greenfield.cognitedata.com"
TEST_TENANT_ID_WRITE: ${{ secrets.TEST_TENANT_ID_WRITE }}
TEST_CLIENT_ID_WRITE: ${{ secrets.TEST_CLIENT_ID_WRITE }}
TEST_CLIENT_SECRET_WRITE: ${{ secrets.TEST_CLIENT_SECRET_WRITE }}
TEST_HOST_READ: "https://api.cognitedata.com"
TEST_TENANT_ID_READ: ${{ secrets.TEST_TENANT_ID_READ }}
TEST_CLIENT_ID_READ: ${{ secrets.TEST_CLIENT_ID_READ }}
TEST_CLIENT_SECRET_READ: ${{ secrets.TEST_CLIENT_SECRET_READ }}
Expand Down
3 changes: 2 additions & 1 deletion CogniteSdk.Types/Alpha/Simulators/SimulatorConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public override SimulatorValue Read(ref Utf8JsonReader reader, Type typeToConver
if (listStr.Count > 0 && listDbl.Count > 0)
{
throw new JsonException("Unable to parse value of type: mixed array");
} else if (listStr.Count > 0)
}
else if (listStr.Count > 0)
{
return SimulatorValue.Create(listStr);
}
Expand Down
30 changes: 30 additions & 0 deletions CogniteSdk.Types/Beta/StreamRecords/Stream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

namespace CogniteSdk.Beta
{
/// <summary>
/// Request to create a stream.
/// </summary>
public class StreamWrite
{
/// <summary>
/// Stream external ID. Must be unique within the project and a valid stream identifier.
/// Stream identifiers can only consist of alphanumeric characters, hyphens, and underscores.
/// It must not start with cdf_ or cognite_, as those are reserved for future use.
/// Stream id cannot be "logs" or "records". Max length is 100 characters.
/// </summary>
public string ExternalId { get; set; }
}

/// <summary>
/// A stream.
/// </summary>
public class Stream : StreamWrite
{
/// <summary>
/// Time the stream was created, in milliseconds since epoch.
/// </summary>
public long CreatedTime { get; set; }
}
}
29 changes: 29 additions & 0 deletions CogniteSdk.Types/Beta/StreamRecords/StreamRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using CogniteSdk.DataModels;

namespace CogniteSdk.Beta
{
/// <summary>
/// A retrieved stream record.
/// </summary>
/// <typeparam name="T">Type of the properties bag.</typeparam>
public class StreamRecord<T>
{
/// <summary>
/// Id of the space the record belongs to.
/// </summary>
public string Space { get; set; }
/// <summary>
/// The number of milliseconds since 00:00:00 Thursday 1 January 1970, Coordinated
/// Unversal Time (UTC) minus leap seconds.
/// </summary>
public long CreatedTime { get; set; }
/// <summary>
/// Spaces to containers to properties and their values for the requested containers.
/// You can use <see cref="StandardInstanceData"/> as a fallback for generic results here.
/// </summary>
public T Properties { get; set; }
}
}
35 changes: 35 additions & 0 deletions CogniteSdk.Types/Beta/StreamRecords/StreamRecordIngest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using CogniteSdk.DataModels;

namespace CogniteSdk.Beta
{
/// <summary>
/// Stream record to ingest.
/// </summary>
public class StreamRecordWrite
{
/// <summary>
/// Id of the space the record belongs to.
/// </summary>
public string Space { get; set; }
/// <summary>
/// List of source properties to write. The properties are from the container(s) making up this record.
/// Note that `InstanceData` is abstract, you should generally use `InstanceData[T]`
/// to assign types to the record item, but since record sources currently only write to
/// containers, it is usually impossible to assign only a single type to the records.
///
/// As a fallback, you can use <see cref="StandardInstanceWriteData"/>.
/// </summary>
public IEnumerable<InstanceData> Sources { get; set; }
}

/// <summary>
/// Insertion request for records.
/// </summary>
public class StreamRecordIngest : ItemsWithoutCursor<StreamRecordWrite>
{
}
}
165 changes: 165 additions & 0 deletions CogniteSdk.Types/Beta/StreamRecords/StreamRecordRetrieve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using System.Text.Json.Serialization;
using CogniteSdk.DataModels;

namespace CogniteSdk.Beta
{
/// <summary>
/// Sources to retrieve stream record data from.
/// </summary>
public class StreamRecordSource
{
/// <summary>
/// Container reference.
/// </summary>
public ContainerIdentifier Source { get; set; }
/// <summary>
/// List of properties to retrieve.
/// </summary>
public IEnumerable<string> Properties { get; set; }
}

/// <summary>
/// Optional attribute to extend the filter with full text search capabilities for
/// a single query in the list of record properties with OR logic.
/// </summary>
public class StreamRecordSearch
{
/// <summary>
/// Query string that will be parsed and used for search.
/// </summary>
public string Query { get; set; }
/// <summary>
/// Array of property identifiers to search through.
/// </summary>
public IEnumerable<IEnumerable<string>> Properties { get; set; }
}

/// <summary>
/// Filter on records created within the provided range.
/// </summary>
public class CreatedTimeFilter
{
/// <summary>
/// Value must be greater than this
/// </summary>
[JsonPropertyName("gt")]
public IDMSValue GreaterThan { get; set; }

/// <summary>
/// Value must be greater than or equal to this
/// </summary>
[JsonPropertyName("gte")]
public IDMSValue GreaterThanEqual { get; set; }

/// <summary>
/// Value must be less than this
/// </summary>
[JsonPropertyName("lt")]
public IDMSValue LessThan { get; set; }

/// <summary>
/// Value must be less than or equal to this
/// </summary>
[JsonPropertyName("lte")]
public IDMSValue LessThanEqual { get; set; }
}

/// <summary>
/// Specification for sorting retrieved records.
/// </summary>
public class StreamRecordsSort
{
/// <summary>
/// Property you want to sort on.
/// </summary>
public IEnumerable<string> Property { get; set; }
/// <summary>
/// Sort direction.
/// </summary>
public SortDirection? Direction { get; set; }
}

/// <summary>
/// Retrieve stream records.
/// </summary>
public class StreamRecordsRetrieve
{
/// <summary>
/// Name of the stream where records are located, required.
/// </summary>
public string Stream { get; set; }
/// <summary>
/// List of containers and the properties that should be selected.
///
/// Optional, if this is left out all properties are returned.
/// </summary>
public IEnumerable<StreamRecordSource> Sources { get; set; }
/// <summary>
/// A filter Domain Specific Language (DSL) used to create advanced filter queries.
///
/// Note that some filter types are not supported, see API docs.
/// </summary>
public IDMSFilter Filter { get; set; }
/// <summary>
/// Matches records with created time within the provided range.
/// </summary>
public CreatedTimeFilter CreatedTime { get; set; }
/// <summary>
/// Maximum number of results to return. Default 10, max 10000.
/// </summary>
public int? Limit { get; set; }
/// <summary>
/// Ordered list of sorting specifications.
/// </summary>
public IEnumerable<StreamRecordsSort> Sort { get; set; }
}


/// <summary>
/// Request for syncing records.
/// </summary>
public class StreamRecordsSync
{
/// <summary>
/// List of containers and the properties that should be selected.
///
/// Optional, if this is left out all properties are returned.
/// </summary>
public IEnumerable<StreamRecordSource> Sources { get; set; }
/// <summary>
/// A filter Domain Specific Language (DSL) used to create advanced filter queries.
///
/// Note that some filter types are not supported, see API docs.
/// </summary>
public IDMSFilter Filter { get; set; }
/// <summary>
/// A cursor returned from the previous sync request.
/// </summary>
public string Cursor { get; set; }
/// <summary>
/// Maximum number of results to return.
/// </summary>
public int? Limit { get; set; }
/// <summary>
/// Initialize cursor. Required if `Cursor` is not set.
/// </summary>
public bool InitializeCursor { get; set; }
}

/// <summary>
/// Response from a sync request.
/// </summary>
/// <typeparam name="T">Type of properties in returned records.</typeparam>
public class StreamRecordsSyncResponse<T> : ItemsWithCursor<StreamRecord<T>>
{
/// <summary>
/// The attribute indiciates if there are more records to read in storage,
/// or if the cursor points to the last item.
/// </summary>
public bool HasNext { get; set; }
}
}
2 changes: 1 addition & 1 deletion CogniteSdk.Types/Common/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private string ReadValue(ref Utf8JsonReader reader, JsonSerializerOptions option
return number.ToString();
}
return reader.GetDouble().ToString();
default:
default:
throw new JsonException($"'{reader.TokenType}' is not supported");
}
}
Expand Down
6 changes: 6 additions & 0 deletions CogniteSdk/src/Resources/Beta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class BetaResource : Resource
/// </summary>
public SubscriptionsResource Subscriptions { get; }

/// <summary>
/// Resource for Stream Records.
/// </summary>
public StreamRecordsResource StreamRecords { get; }

/// <summary>
/// Will only be instantiated by the client.
/// </summary>
Expand All @@ -34,6 +39,7 @@ internal BetaResource(Func<CancellationToken, Task<string>> authHandler, FSharpF
{
Templates = new TemplatesResource(authHandler, ctx);
Subscriptions = new SubscriptionsResource(authHandler, ctx);
StreamRecords = new StreamRecordsResource(authHandler, ctx);
}
}
}
Loading
Loading