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

chore: add support 8.16.2 to go-kibana-rest and acc tests #964

Merged
merged 5 commits into from
Dec 19, 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
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ jobs:
- '8.13.4'
- '8.14.3'
- '8.15.5'
- '8.16.2'
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
Expand Down Expand Up @@ -153,7 +154,7 @@ jobs:

- id: setup-fleet
name: Setup Fleet
if: matrix.version == '8.10.3' || matrix.version == '8.11.4' || matrix.version == '8.12.2' || matrix.version == '8.13.4' || matrix.version == '8.14.3' || matrix.version == '8.15.5'
if: matrix.version == '8.10.3' || matrix.version == '8.11.4' || matrix.version == '8.12.2' || matrix.version == '8.13.4' || matrix.version == '8.14.3' || matrix.version == '8.15.5' || matrix.version == '8.16.2'
run: |-
make setup-kibana-fleet
env:
Expand All @@ -162,7 +163,7 @@ jobs:

- id: force-install-synthetics
name: Force install synthetics
if: matrix.version == '8.14.3' || matrix.version == '8.15.5'
if: matrix.version == '8.14.3' || matrix.version == '8.15.5' || matrix.version == '8.16.2'
run: |-
for i in {1..5}; do curl -s -H "Authorization: ApiKey ${{ steps.get-api-key.outputs.apikey }}" --header "Content-Type: application/json" --header "kbn-xsrf: true" --request POST --data '{ "force": true }' http://localhost:5601/api/fleet/epm/packages/synthetics/1.2.2 && break || sleep 15; done

Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Acceptance tests

```bash
make docker-testacc
```

Run a single test with terraform debug enabled:
```bash
make docker-testacc TF_LOG=DEBUG TESTARGS='-run ^TestAccResourceDataStreamLifecycle$$'
```
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SWAGGER_VERSION ?= 8.7

GOVERSION ?= $(shell grep -e '^go' go.mod | cut -f 2 -d ' ')

STACK_VERSION ?= 8.15.5
STACK_VERSION ?= 8.16.2

ELASTICSEARCH_NAME ?= terraform-elasticstack-es
ELASTICSEARCH_ENDPOINTS ?= http://$(ELASTICSEARCH_NAME):9200
Expand Down
7 changes: 5 additions & 2 deletions internal/clients/elasticsearch/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,14 @@ func GetDataStreamLifecycle(ctx context.Context, apiClient *clients.ApiClient, d
return nil, utils.FrameworkDiagsFromSDK(diags)
}

dStreams := make(map[string][]models.DataStreamLifecycle)
dStreams := struct {
DataStreams []models.DataStreamLifecycle `json:"data_streams,omitempty"`
}{}

if err := json.NewDecoder(res.Body).Decode(&dStreams); err != nil {
return nil, utils.FrameworkDiagFromError(err)
}
ds := dStreams["data_streams"]
ds := dStreams.DataStreams
return &ds, nil
}

Expand Down
7 changes: 5 additions & 2 deletions internal/fleet/integration_policy/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func TestAccResourceIntegrationPolicy(t *testing.T) {
func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)

sdkConstrains, err := version.NewConstraint(">=8.10.0,<8.16.0")
biscout42 marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
CheckDestroy: checkResourceIntegrationPolicyDestroy,
Expand All @@ -86,7 +89,7 @@ func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
VersionConstraint: "0.11.7",
},
},
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
SkipFunc: versionutils.CheckIfVersionMeetsConstraints(sdkConstrains),
Config: testAccResourceIntegrationPolicySecretsCreate(policyName, "created"),
ExpectNonEmptyPlan: true, // secret churn
Check: resource.ComposeTestCheckFunc(
Expand All @@ -103,7 +106,7 @@ func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
},
{
ProtoV6ProviderFactories: acctest.Providers,
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
SkipFunc: versionutils.CheckIfVersionMeetsConstraints(sdkConstrains),
Config: testAccResourceIntegrationPolicySecretsCreate(policyName, "created"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "name", policyName),
Expand Down
7 changes: 2 additions & 5 deletions internal/kibana/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,11 @@ func resourceRoleUpsert(ctx context.Context, d *schema.ResourceData, meta interf
if err != nil {
return diag.FromErr(err)
}
queryParams := ""
if d.IsNewResource() {
queryParams = "?createOnly=true"
}
kibanaRole := kbapi.KibanaRole{
Name: fmt.Sprintf("%s%s", d.Get("name").(string), queryParams),
Name: d.Get("name").(string),
Kibana: []kbapi.KibanaRoleKibana{},
Elasticsearch: &kbapi.KibanaRoleElasticsearch{},
CreateOnly: d.IsNewResource(),
}

if v, ok := d.GetOk("kibana"); ok {
Expand Down
15 changes: 15 additions & 0 deletions libs/go-kibana-rest/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Unit tests

To run the unit tests, you can use the following command:
```bash

docker compose up -d
make test
```

One could enable debug output for tests by setting environment variable `DEBUG=true`, that helps to see http requests and responses.

Here is an example of environment variables to run a single test, e.g. from IDE or CLI:
```bash
DEBUG=true TEST="-run TestKBAPITestSuite/TestKibanaSpaces ./..." make test
```
7 changes: 3 additions & 4 deletions libs/go-kibana-rest/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.16.1@sha256:500b04e9282aeffd083fb8f917ee2c309c99f76c095c79681bd77ab37d6886e6
image: docker.elastic.co/elasticsearch/elasticsearch:8.16.2
environment:
cluster.name: test
discovery.type: single-node
Expand All @@ -11,7 +11,7 @@ services:
ports:
- "9200:9200/tcp"
set-kibana-password:
image: docker.elastic.co/kibana/kibana:8.16.1@sha256:a22f9f9bb16fc7b01cfd03523a2d5a0d9873daefec6092368a8e2bb0b3380757
image: docker.elastic.co/kibana/kibana:8.16.2
restart: on-failure
links:
- elasticsearch
Expand All @@ -22,14 +22,13 @@ services:
elasticsearch:
condition: service_started
kibana:
image: docker.elastic.co/kibana/kibana:8.16.1@sha256:a22f9f9bb16fc7b01cfd03523a2d5a0d9873daefec6092368a8e2bb0b3380757
image: docker.elastic.co/kibana/kibana:8.16.2
environment:
SERVER_NAME: kibana
ELASTICSEARCH_HOSTS: http://es:9200
ELASTICSEARCH_USERNAME: kibana_system
ELASTICSEARCH_PASSWORD: changeme
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: min-32-byte-long-strong-encryption-key
# LOGGING_ROOT_LEVEL: debug
links:
- elasticsearch:es
ports:
Expand Down
7 changes: 6 additions & 1 deletion libs/go-kibana-rest/kbapi/api.kibana_role_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type KibanaRole struct {
TransientMedata *KibanaRoleTransientMetadata `json:"transient_metadata,omitempty"`
Elasticsearch *KibanaRoleElasticsearch `json:"elasticsearch,omitempty"`
Kibana []KibanaRoleKibana `json:"kibana,omitempty"`
CreateOnly bool `json:"-"`
}

// KibanaRoleTransientMetadata is the API TransientMedata object
Expand Down Expand Up @@ -153,7 +154,11 @@ func newKibanaRoleManagementCreateOrUpdateFunc(c *resty.Client) KibanaRoleManage
if err != nil {
return nil, err
}
resp, err := c.R().SetBody(jsonData).Put(path)
r := c.R()
if kibanaRole.CreateOnly {
r = r.SetQueryParam("createOnly", "true")
}
resp, err := r.SetBody(jsonData).Put(path)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion libs/go-kibana-rest/kbapi/api.kibana_spaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *KBAPITestSuite) TestKibanaSpaces() {
Objects: []KibanaSpaceObjectParameter{
{
Type: "config",
ID: "8.15.0",
ID: "8.16.2",
},
},
}
Expand Down
19 changes: 0 additions & 19 deletions libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"testing"
"time"

"github.com/go-resty/resty/v2"
"github.com/google/uuid"
Expand Down Expand Up @@ -369,7 +368,6 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
monitor, err := syntheticsAPI.Monitor.Add(ctx, config, fields, space)
assert.NoError(s.T(), err)
assert.NotNil(s.T(), monitor)
updateDueToKibanaAPIDiff(monitor)

get, err := syntheticsAPI.Monitor.Get(ctx, monitor.Id, space)
assert.NoError(s.T(), err)
Expand All @@ -382,11 +380,9 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
update, err := syntheticsAPI.Monitor.Update(ctx, monitor.Id, tc.update.config, tc.update.fields, space)
assert.NoError(s.T(), err)
assert.NotNil(s.T(), update)
updateDueToKibanaAPIDiff(update)

get, err = syntheticsAPI.Monitor.Get(ctx, monitor.ConfigId, space)
assert.NoError(s.T(), err)
get.CreatedAt = time.Time{} // update response doesn't have created_at field
assert.Equal(s.T(), update, get)

deleted, err := syntheticsAPI.Monitor.Delete(ctx, space, monitor.ConfigId)
Expand All @@ -410,21 +406,6 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
}
}

// see https://github.com/elastic/kibana/issues/189906
func updateDueToKibanaAPIDiff(m *SyntheticsMonitor) {
m.Params = nil
m.Username = ""
m.Password = ""
m.ProxyHeaders = nil
m.CheckResponseBodyPositive = nil
m.CheckRequestBody = nil
m.CheckRequestHeaders = nil
m.CheckSend = ""
m.CheckReceive = ""
m.InlineScript = ""
m.SyntheticsArgs = nil
}

func (s *KBAPITestSuite) TestKibanaSyntheticsPrivateLocationAPI() {

ctx := context.Background()
Expand Down
Loading