Skip to content

Commit

Permalink
Field, Function and test fixes, adding missing struct to node stats (#…
Browse files Browse the repository at this point in the history
…572)

* opensearchapi: add caches field to nodes stats

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* internal: fix test help json compare when object is null

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* plugins: adjust role struct fls from string to slice

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* opensearchapi: fixes wrong response parsing for indices mapping and recovery

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* plugins/security: fixes wrong response parsing for get requests

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* plugins/security: roles get response struct has its own sub structs without omitempty

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

---------

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
  • Loading branch information
Jakob3xD authored Jun 27, 2024
1 parent ad14bb2 commit dbe714b
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds the `Routing` field in SearchHit interface. ([#516](https://github.com/opensearch-project/opensearch-go/pull/516))
- Adds the `SearchPipelines` field to `SearchParams` ([#532](https://github.com/opensearch-project/opensearch-go/pull/532))
- Adds support for OpenSearch 2.14 ([#552](https://github.com/opensearch-project/opensearch-go/pull/552))
- Adds the `Caches` field to Node stats ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))

### Changed
- Security roles get response struct has its own sub structs without omitempty ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))

### Deprecated

Expand All @@ -19,6 +21,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Fixes empty request body on retry with compression enabled ([#543](https://github.com/opensearch-project/opensearch-go/pull/543))
- Fixes `Conditions` in `PolicyStateTransition` of ISM plugin ([#556](https://github.com/opensearch-project/opensearch-go/pull/556))
- Fixes integration test response validation when response is null ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))
- Adjust security Role struct for FLS from string to []string ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))
- Fixes wrong response parsing for indices mapping and recovery ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))
- Fixes wrong response parsing for security get requests ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))

### Security

Expand Down
2 changes: 1 addition & 1 deletion internal/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func CompareRawJSONwithParsedJSON(t *testing.T, resp any, rawResp *opensearch.Re
operations := make([]jsondiff.Operation, 0)
for _, operation := range patch {
// different opensearch version added more field, only check if we miss some fields
if operation.Type != "add" {
if operation.Type != "add" || (operation.Type == "add" && operation.Path == "") {
operations = append(operations, operation)
}
}
Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api_indices-mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c mappingClient) Field(ctx context.Context, req *MappingFieldReq) (*Mappin
data MappingFieldResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil {
return &data, err
}

Expand Down
2 changes: 1 addition & 1 deletion opensearchapi/api_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (c indicesClient) Recovery(ctx context.Context, req *IndicesRecoveryReq) (*
data IndicesRecoveryResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil {
return &data, err
}

Expand Down
15 changes: 14 additions & 1 deletion opensearchapi/api_nodes-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type NodesStats struct {
SegmentReplicationBackpressure NodesStatsSegmentReplicationBackpressure `json:"segment_replication_backpressure"`
Repositories []json.RawMessage `json:"repositories"`
AdmissionControl NodesStatsAdmissionControl `json:"admission_control"`
Caches NodesStatsCaches `json:"caches"`
}

// NodesStatsIndices is a sub type of NodesStats representing Indices information of the node
Expand Down Expand Up @@ -702,7 +703,7 @@ type NodesStatsSegmentReplicationBackpressure struct {
TotalRejectedRequests int `json:"total_rejected_requests"`
}

// NodesStatsAdmissionControl is a sub of NodesStats
// NodesStatsAdmissionControl is a sub type of NodesStats
type NodesStatsAdmissionControl struct {
GlobalCPUUsage struct {
Transport struct {
Expand All @@ -715,3 +716,15 @@ type NodesStatsAdmissionControl struct {
} `json:"transport"`
} `json:"global_io_usage"`
}

// NodesStatsCaches is a sub type of NodesStats
type NodesStatsCaches struct {
RequestCache struct {
SizeInBytes int `json:"size_in_bytes"`
Evictions int `json:"evictions"`
HitCount int `json:"hit_count"`
MissCount int `json:"miss_count"`
ItemCount int `json:"item_count"`
StoreName string `json:"store_name"`
} `json:"request_cache"`
}
2 changes: 1 addition & 1 deletion plugins/security/api_actiongroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c actiongroupsClient) Get(ctx context.Context, req *ActionGroupsGetReq) (A
data ActionGroupsGetResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Groups); err != nil {
return data, err
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/security/api_internalusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c internalusersClient) Get(ctx context.Context, req *InternalUsersGetReq)
data InternalUsersGetResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Users); err != nil {
return data, err
}

Expand Down
29 changes: 22 additions & 7 deletions plugins/security/api_roles-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,26 @@ func (r RolesGetResp) Inspect() Inspect {

// RolesGetItem is a sub type of RolesGetResp containing information about a role
type RolesGetItem struct {
Reserved bool `json:"reserved"`
Hidden bool `json:"hidden"`
Description string `json:"description"`
ClusterPermissions []string `json:"cluster_permissions"`
IndexPermissions []RolesIndexPermission `json:"index_permissions"`
TenantPermissions []RolesTenantPermission `json:"tenant_permissions"`
Statis bool `json:"static"`
Reserved bool `json:"reserved"`
Hidden bool `json:"hidden"`
Description string `json:"description"`
ClusterPermissions []string `json:"cluster_permissions"`
IndexPermissions []RolesGetIndexPermission `json:"index_permissions"`
TenantPermissions []RolesGetTenantPermission `json:"tenant_permissions"`
Statis bool `json:"static"`
}

// RolesGetIndexPermission contains index permissions and is used for Get and Put requests
type RolesGetIndexPermission struct {
IndexPatterns []string `json:"index_patterns"`
DLS string `json:"dls"`
FLS []string `json:"fls"`
MaskedFields []string `json:"masked_fields"`
AllowedActions []string `json:"allowed_actions"`
}

// RolesGetTenantPermission contains tenant permissions and is used for Get and Put requests
type RolesGetTenantPermission struct {
TenantPatterns []string `json:"tenant_patterns"`
AllowedActions []string `json:"allowed_actions"`
}
15 changes: 15 additions & 0 deletions plugins/security/api_roles-put.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ type RolesPutResp struct {
func (r RolesPutResp) Inspect() Inspect {
return Inspect{Response: r.response}
}

// RolesIndexPermission contains index permissions and is used for Get and Put requests
type RolesIndexPermission struct {
IndexPatterns []string `json:"index_patterns,omitempty"`
DLS string `json:"dls,omitempty"`
FLS []string `json:"fls,omitempty"`
MaskedFields []string `json:"masked_fields,omitempty"`
AllowedActions []string `json:"allowed_actions,omitempty"`
}

// RolesTenantPermission contains tenant permissions and is used for Get and Put requests
type RolesTenantPermission struct {
TenantPatterns []string `json:"tenant_patterns,omitempty"`
AllowedActions []string `json:"allowed_actions,omitempty"`
}
17 changes: 1 addition & 16 deletions plugins/security/api_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c rolesClient) Get(ctx context.Context, req *RolesGetReq) (RolesGetResp, e
data RolesGetResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Roles); err != nil {
return data, err
}

Expand Down Expand Up @@ -69,18 +69,3 @@ func (c rolesClient) Patch(ctx context.Context, req RolesPatchReq) (RolesPatchRe

return data, nil
}

// RolesIndexPermission contains index permissions and is used for Get and Put requests
type RolesIndexPermission struct {
IndexPatterns []string `json:"index_patterns,omitempty"`
DLS string `json:"dls,omitempty"`
FLS string `json:"fls,omitempty"`
MaskedFields []string `json:"masked_fields,omitempty"`
AllowedActions []string `json:"allowed_actions,omitempty"`
}

// RolesTenantPermission contains tenant permissions and is used for Get and Put requests
type RolesTenantPermission struct {
TenantPatterns []string `json:"tenant_patterns,omitempty"`
AllowedActions []string `json:"allowed_actions,omitempty"`
}
2 changes: 1 addition & 1 deletion plugins/security/api_rolesmapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c rolesmappingClient) Get(ctx context.Context, req *RolesMappingGetReq) (R
data RolesMappingGetResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.RolesMapping); err != nil {
return data, err
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/security/api_tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c tenantsClient) Get(ctx context.Context, req *TenantsGetReq) (TenantsGetR
data TenantsGetResp
err error
)
if data.response, err = c.apiClient.do(ctx, req, &data); err != nil {
if data.response, err = c.apiClient.do(ctx, req, &data.Tenants); err != nil {
return data, err
}

Expand Down

0 comments on commit dbe714b

Please sign in to comment.