Skip to content

Commit

Permalink
Add support for indices.stats (opensearch-project#753)
Browse files Browse the repository at this point in the history
* Add support for indices.stats

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Add changelog entry

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix tests

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix another test

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix more tests

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia committed Aug 13, 2024
1 parent 3aa052b commit 43ba0de
Show file tree
Hide file tree
Showing 24 changed files with 1,336 additions and 576 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added support for the `Cat.PitSegments` and `Cat.SegmentReplication` APIs ([#527](https://github.com/opensearch-project/opensearch-net/pull/527))
- Added support for serializing the `DateOnly` and `TimeOnly` types ([#734](https://github.com/opensearch-project/opensearch-net/pull/734))
- Added support for the `Ext` parameter on `SearchRequest` ([#738](https://github.com/opensearch-project/opensearch-net/pull/738))
- Added support for the `Indices.Stats` API ([#753](https://github.com/opensearch-project/opensearch-net/pull/753))

### Removed
- Removed support for the `net461` target ([#256](https://github.com/opensearch-project/opensearch-net/pull/256))
Expand Down
1 change: 1 addition & 0 deletions src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static class CodeConfiguration
new("dangling_indices.*"),

new("indices.{delete,exists,get,put}_index_template"),
new("indices.stats"),

new("ingest.*"),
new("nodes.*"),
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/OpenSearch.Client/ApiUrlsLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ internal static partial class ApiUrlsLookups
internal static ApiUrls IndicesShardStores = new ApiUrls(new[]{"_shard_stores", "{index}/_shard_stores"});
internal static ApiUrls IndicesShrink = new ApiUrls(new[]{"{index}/_shrink/{target}"});
internal static ApiUrls IndicesSplit = new ApiUrls(new[]{"{index}/_split/{target}"});
internal static ApiUrls IndicesStats = new ApiUrls(new[]{"_stats", "_stats/{metric}", "{index}/_stats", "{index}/_stats/{metric}"});
internal static ApiUrls IndicesBulkAlias = new ApiUrls(new[]{"_aliases"});
internal static ApiUrls IndicesValidateQuery = new ApiUrls(new[]{"_validate/query", "{index}/_validate/query"});
internal static ApiUrls NoNamespaceRootNodeInfo = new ApiUrls(new[]{""});
Expand Down
22 changes: 22 additions & 0 deletions src/OpenSearch.Client/Indices/Stats/IndicesStatsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

namespace OpenSearch.Client;

[MapsApi("indices.stats")]
[ReadAs(typeof(IndicesStatsRequest))]
public partial interface IIndicesStatsRequest
{
}

public partial class IndicesStatsRequest
{
}

public partial class IndicesStatsDescriptor
{
}
244 changes: 244 additions & 0 deletions src/OpenSearch.Client/Indices/Stats/IndicesStatsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using System.Collections.Generic;
using System.Runtime.Serialization;
using OpenSearch.Net;
using OpenSearch.Net.Utf8Json;

namespace OpenSearch.Client;

[DataContract]
public class IndicesStatsResponse : ResponseBase
{
[DataMember(Name = "_all")]
public AllIndicesStats All { get; internal set; }

[DataMember(Name = "_shards")]
public ShardStatistics Shards { get; internal set; }

[DataMember(Name = "indices")]
public IndicesStatsDictionary Indices { get; internal set; }
}

[JsonFormatter(typeof(Converter))]
public class IndicesStatsDictionary : ResolvableDictionaryProxy<IndexName, IndicesStats>
{
private IndicesStatsDictionary(IConnectionConfigurationValues s, IReadOnlyDictionary<IndexName, IndicesStats> d)
: base(s, d) { }

private class Converter : ResolvableDictionaryFormatterBase<IndicesStatsDictionary, IndexName, IndicesStats>
{
protected override IndicesStatsDictionary Create(IConnectionSettingsValues s, Dictionary<IndexName, IndicesStats> d) => new(s, d);
}
}

[DataContract]
public class AllIndicesStats
{
[DataMember(Name = "primaries")]
public IndexStats Primaries { get; internal set; }

[DataMember(Name = "total")]
public IndexStats Total { get; internal set; }
}

[DataContract]
public class IndicesStats
{
[DataMember(Name = "uuid")]
public string Uuid { get; internal set; }

[DataMember(Name = "primaries")]
public IndexStats Primaries { get; internal set; }

[DataMember(Name = "total")]
public IndexStats Total { get; internal set; }

[DataMember(Name = "shards")]
public IReadOnlyDictionary<string, IReadOnlyCollection<IndexShardStats>> Shards { get; internal set; }
}

[DataContract]
public abstract class IndexStatsBase
{
[DataMember(Name = "docs")]
public DocStats Documents { get; internal set; }

[DataMember(Name = "store")]
public StoreStats Store { get; internal set; }

[DataMember(Name = "indexing")]
public IndexingStats Indexing { get; internal set; }

[DataMember(Name = "get")]
public GetStats Get { get; internal set; }

[DataMember(Name = "search")]
public SearchStats Search { get; internal set; }

[DataMember(Name = "merges")]
public MergesStats Merges { get; internal set; }

[DataMember(Name = "refresh")]
public RefreshStats Refresh { get; internal set; }

[DataMember(Name = "flush")]
public FlushStats Flush { get; internal set; }

[DataMember(Name = "warmer")]
public WarmerStats Warmer { get; internal set; }

[DataMember(Name = "query_cache")]
public QueryCacheStats QueryCache { get; internal set; }

[DataMember(Name = "fielddata")]
public FielddataStats Fielddata { get; internal set; }

[DataMember(Name = "completion")]
public CompletionStats Completion { get; internal set; }

[DataMember(Name = "segments")]
public SegmentsStats Segments { get; internal set; }

[DataMember(Name = "translog")]
public TranslogStats Translog { get; internal set; }

[DataMember(Name = "request_cache")]
public RequestCacheStats RequestCache { get; internal set; }

[DataMember(Name = "recovery")]
public RecoveryStats Recovery { get; internal set; }
}

[DataContract]
public class IndexStats : IndexStatsBase
{

}

[DataContract]
public class IndexShardStats : IndexStatsBase
{
[DataMember(Name = "routing")]
public ShardRouting Routing { get; internal set; }

[DataMember(Name = "commit")]
public ShardCommitStats Commit { get; internal set; }

[DataMember(Name = "seq_no")]
public ShardSequenceNumberStats SequenceNumber { get; internal set; }

[DataMember(Name = "retention_leases")]
public ShardRetentionLeasesStats RetentionLeases { get; internal set; }

[DataMember(Name = "shard_path")]
public ShardPath ShardPath { get; internal set; }
}

[DataContract]
public class ShardRouting
{
[DataMember(Name = "state")]
public ShardRoutingState State { get; internal set; }

[DataMember(Name = "primary")]
public bool Primary { get; internal set; }

[DataMember(Name = "node")]
public string Node { get; internal set; }

[DataMember(Name = "relocating_node")]
public string RelocatingNode { get; internal set; }
}

[StringEnum]
public enum ShardRoutingState
{
[EnumMember(Value = "INITIALIZING")]
Initializing,

[EnumMember(Value = "RELOCATING")]
Relocating,

[EnumMember(Value = "STARTED")]
Started,

[EnumMember(Value = "UNASSIGNED")]
Unassigned
}

[DataContract]
public class ShardCommitStats
{
[DataMember(Name = "id")]
public string Id { get; internal set; }

[DataMember(Name = "generation")]
public long Generation { get; internal set; }

[DataMember(Name = "num_docs")]
public int NumDocs { get; internal set; }

[DataMember(Name = "user_data")]
public IReadOnlyDictionary<string, string> UserData { get; internal set; }
}

[DataContract]
public class ShardSequenceNumberStats
{
[DataMember(Name = "max_seq_no")]
public long MaxSequenceNumber { get; internal set; }

[DataMember(Name = "local_checkpoint")]
public long LocalCheckpoint { get; internal set; }

[DataMember(Name = "global_checkpoint")]
public long GlobalCheckpoint { get; internal set; }
}

[DataContract]
public class ShardRetentionLeasesStats
{
[DataMember(Name = "primary_term")]
public long PrimaryTerm { get; internal set; }

[DataMember(Name = "version")]
public long Version { get; internal set; }

[DataMember(Name = "leases")]
public IReadOnlyCollection<ShardRetentionLease> Leases { get; internal set; }
}

[DataContract]
public class ShardRetentionLease
{
[DataMember(Name = "id")]
public string Id { get; internal set; }

[DataMember(Name = "retaining_seq_no")]
public long RetainingSequenceNumber { get; internal set; }

[DataMember(Name = "timestamp")]
public long Timestamp { get; internal set; }

[DataMember(Name = "source")]
public string Source { get; internal set; }
}

[DataContract]
public class ShardPath
{
[DataMember(Name = "state_path")]
public string StatePath { get; internal set; }

[DataMember(Name = "data_path")]
public string DataPath { get; internal set; }

[DataMember(Name = "is_custom_data_path")]
public bool IsCustomDataPath { get; internal set; }
}
3 changes: 3 additions & 0 deletions src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ internal static partial class ApiUrlsLookups
internal static readonly ApiUrls IndicesPutComposableTemplate =
new(new[] { "_index_template/{name}" });

internal static readonly ApiUrls IndicesStats =
new(new[] { "_stats", "{index}/_stats", "{index}/_stats/{metric}", "_stats/{metric}" });

internal static readonly ApiUrls IngestDeletePipeline =
new(new[] { "_ingest/pipeline/{id}" });

Expand Down
Loading

0 comments on commit 43ba0de

Please sign in to comment.