Skip to content

Commit

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

Signed-off-by: Thomas Farr <[email protected]>

* Add changelog entry

Signed-off-by: Thomas Farr <[email protected]>

* Fix tests

Signed-off-by: Thomas Farr <[email protected]>

* Fix another test

Signed-off-by: Thomas Farr <[email protected]>

* Fix more tests

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 43ba0de)
  • Loading branch information
Xtansia committed Aug 14, 2024
1 parent 47c4695 commit a12fc5f
Show file tree
Hide file tree
Showing 26 changed files with 1,325 additions and 598 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624))
- 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))

### Dependencies
- Bumps `AWSSDK.Core` from 3.7.204.12 to 3.7.400.4
Expand Down
3 changes: 2 additions & 1 deletion src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static class CodeConfiguration
new("cat.{all_pit,pit}_segments"),
new("cat.segment_replication"),
new("cluster.{delete,exists,get,put}_component_template"),
new("indices.{delete,exists,get,put}_index_template")
new("indices.{delete,exists,get,put}_index_template"),
new("indices.stats")
};

public static bool IncludeOperation(string name) => OperationsToInclude.Any(g => g.IsMatch(name));
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 @@ -118,7 +118,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 @@ -88,5 +88,8 @@ 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}" });
}
}
Loading

0 comments on commit a12fc5f

Please sign in to comment.