Skip to content

Commit c5572e7

Browse files
committed
fix: use namespace and space_id in synthetics separately
1 parent 189a287 commit c5572e7

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

libs/go-kibana-rest/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
ports:
1212
- "9200:9200/tcp"
1313
set-kibana-password:
14-
image: docker.elastic.co/kibana/kibana:9.1.2@sha256:dea5d20df42e6833966deceadb10ecdbf85970b704d17b0abfc3b485622c1a08
14+
image: docker.elastic.co/kibana/kibana:9.0.3@sha256:c4c00a485fbc3619d8373f3bc74e9dd5b5a34380ef50442be4366e8fb57cd50a
1515
restart: on-failure
1616
links:
1717
- elasticsearch
@@ -22,7 +22,7 @@ services:
2222
elasticsearch:
2323
condition: service_started
2424
kibana:
25-
image: docker.elastic.co/kibana/kibana:9.1.2@sha256:dea5d20df42e6833966deceadb10ecdbf85970b704d17b0abfc3b485622c1a08
25+
image: docker.elastic.co/kibana/kibana:9.0.3@sha256:c4c00a485fbc3619d8373f3bc74e9dd5b5a34380ef50442be4366e8fb57cd50a
2626
environment:
2727
SERVER_NAME: kibana
2828
ELASTICSEARCH_HOSTS: http://es:9200

libs/go-kibana-rest/kbapi/api.kibana_synthetics.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ func (f BrowserMonitorFields) APIRequest(config SyntheticsMonitorConfig) interfa
326326
}
327327
}
328328

329-
type KibanaSyntheticsMonitorAdd func(ctx context.Context, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error)
329+
type KibanaSyntheticsMonitorAdd func(ctx context.Context, config SyntheticsMonitorConfig, fields MonitorFields, space string) (*SyntheticsMonitor, error)
330330

331-
type KibanaSyntheticsMonitorUpdate func(ctx context.Context, id MonitorID, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error)
331+
type KibanaSyntheticsMonitorUpdate func(ctx context.Context, id MonitorID, config SyntheticsMonitorConfig, fields MonitorFields, space string) (*SyntheticsMonitor, error)
332332

333-
type KibanaSyntheticsMonitorGet func(ctx context.Context, id MonitorID, namespace string) (*SyntheticsMonitor, error)
333+
type KibanaSyntheticsMonitorGet func(ctx context.Context, id MonitorID, space string) (*SyntheticsMonitor, error)
334334

335-
type KibanaSyntheticsMonitorDelete func(ctx context.Context, namespace string, ids ...MonitorID) ([]MonitorDeleteStatus, error)
335+
type KibanaSyntheticsMonitorDelete func(ctx context.Context, space string, ids ...MonitorID) ([]MonitorDeleteStatus, error)
336336

337337
type KibanaSyntheticsPrivateLocationCreate func(ctx context.Context, pLoc PrivateLocationConfig) (*PrivateLocation, error)
338338

@@ -390,8 +390,8 @@ func newKibanaSyntheticsPrivateLocationDeleteFunc(c *resty.Client) KibanaSynthet
390390
}
391391

392392
func newKibanaSyntheticsMonitorGetFunc(c *resty.Client) KibanaSyntheticsMonitorGet {
393-
return func(ctx context.Context, id MonitorID, namespace string) (*SyntheticsMonitor, error) {
394-
path := basePathWithId(namespace, monitorsSuffix, id)
393+
return func(ctx context.Context, id MonitorID, space string) (*SyntheticsMonitor, error) {
394+
path := basePathWithId(space, monitorsSuffix, id)
395395
log.Debugf("URL to get monitor: %s", path)
396396

397397
resp, err := c.R().SetContext(ctx).Get(path)
@@ -403,8 +403,8 @@ func newKibanaSyntheticsMonitorGetFunc(c *resty.Client) KibanaSyntheticsMonitorG
403403
}
404404

405405
func newKibanaSyntheticsMonitorDeleteFunc(c *resty.Client) KibanaSyntheticsMonitorDelete {
406-
return func(ctx context.Context, namespace string, ids ...MonitorID) ([]MonitorDeleteStatus, error) {
407-
path := basePath(namespace, monitorsSuffix)
406+
return func(ctx context.Context, space string, ids ...MonitorID) ([]MonitorDeleteStatus, error) {
407+
path := basePath(space, monitorsSuffix)
408408
log.Debugf("URL to delete monitors: %s", path)
409409

410410
resp, err := c.R().SetContext(ctx).SetBody(map[string]interface{}{
@@ -420,9 +420,9 @@ func newKibanaSyntheticsMonitorDeleteFunc(c *resty.Client) KibanaSyntheticsMonit
420420
}
421421

422422
func newKibanaSyntheticsMonitorUpdateFunc(c *resty.Client) KibanaSyntheticsMonitorUpdate {
423-
return func(ctx context.Context, id MonitorID, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error) {
423+
return func(ctx context.Context, id MonitorID, config SyntheticsMonitorConfig, fields MonitorFields, space string) (*SyntheticsMonitor, error) {
424424

425-
path := basePathWithId(namespace, monitorsSuffix, id)
425+
path := basePathWithId(space, monitorsSuffix, id)
426426
log.Debugf("URL to update monitor: %s", path)
427427
data := fields.APIRequest(config)
428428
resp, err := c.R().SetContext(ctx).SetBody(data).Put(path)
@@ -434,9 +434,9 @@ func newKibanaSyntheticsMonitorUpdateFunc(c *resty.Client) KibanaSyntheticsMonit
434434
}
435435

436436
func newKibanaSyntheticsMonitorAddFunc(c *resty.Client) KibanaSyntheticsMonitorAdd {
437-
return func(ctx context.Context, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error) {
437+
return func(ctx context.Context, config SyntheticsMonitorConfig, fields MonitorFields, space string) (*SyntheticsMonitor, error) {
438438

439-
path := basePath(namespace, monitorsSuffix)
439+
path := basePath(space, monitorsSuffix)
440440
log.Debugf("URL to create monitor: %s", path)
441441
data := fields.APIRequest(config)
442442
resp, err := c.R().SetContext(ctx).SetBody(data).Post(path)
@@ -510,18 +510,18 @@ func handleKibanaError(err error, resp *resty.Response) error {
510510
return nil
511511
}
512512

513-
func basePathWithId(namespace, suffix string, id any) string {
514-
return fmt.Sprintf("%s/%s", basePath(namespace, suffix), id)
513+
func basePathWithId(space, suffix string, id any) string {
514+
return fmt.Sprintf("%s/%s", basePath(space, suffix), id)
515515
}
516516

517-
func basePath(namespace, suffix string) string {
518-
return namespaceBasesPath(namespace, basePathKibanaSynthetics, suffix)
517+
func basePath(space, suffix string) string {
518+
return spaceBasesPath(space, basePathKibanaSynthetics, suffix)
519519
}
520520

521-
func namespaceBasesPath(namespace, basePath, suffix string) string {
522-
if namespace == "" || namespace == "default" {
521+
func spaceBasesPath(space, basePath, suffix string) string {
522+
if space == "" || space == "default" {
523523
return fmt.Sprintf("%s%s", basePath, suffix)
524524
}
525525

526-
return fmt.Sprintf("/s/%s%s%s", namespace, basePath, suffix)
526+
return fmt.Sprintf("/s/%s%s%s", space, basePath, suffix)
527527
}

libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strings"
78
"testing"
89

910
"github.com/go-resty/resty/v2"
@@ -12,22 +13,22 @@ import (
1213
)
1314

1415
var (
15-
spaces = []string{"", "default", "testacc"}
16+
spaces = []string{"", "default", "testacc", "sample-with-dash"}
1617
)
1718

18-
func testWithPolicy(t *testing.T, client *resty.Client, namespace string, f func(policyId string)) {
19+
func testWithPolicy(t *testing.T, client *resty.Client, space_id string, f func(policyId string)) {
1920

2021
policyName := uuid.New().String()
21-
path := namespaceBasesPath(namespace, "/api/fleet", "/agent_policies")
22+
path := spaceBasesPath(space_id, "/api/fleet", "/agent_policies")
2223

23-
if namespace == "" {
24-
namespace = "default"
24+
if space_id == "" {
25+
space_id = "default"
2526
}
2627

2728
policyResponse, err := client.R().SetBody(map[string]interface{}{
2829
"name": fmt.Sprintf("Test synthetics monitor policy %s", policyName),
2930
"description": "test policy for synthetics API",
30-
"namespace": namespace,
31+
"namespace": strings.Replace(space_id, "-", "_", -1),
3132
"monitoring_enabled": []string{"logs", "metrics"},
3233
}).Post(path)
3334
assert.NoError(t, err)
@@ -64,6 +65,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
6465
for _, n := range spaces {
6566
testUuid := uuid.New().String()
6667
space := n
68+
namespace := strings.Replace(n, "-", "_", -1)
6769
syntheticsAPI := s.API.KibanaSynthetics
6870

6971
testWithPolicy(s.T(), s.client, space, func(policyId string) {
@@ -138,7 +140,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
138140
},
139141
APMServiceName: "APMServiceName",
140142
TimeoutSeconds: 42,
141-
Namespace: space,
143+
Namespace: namespace,
142144
Params: map[string]interface{}{
143145
"param1": "some-params",
144146
"my_url": "http://localhost:8080",
@@ -212,7 +214,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
212214
},
213215
APMServiceName: "APMServiceName",
214216
TimeoutSeconds: 42,
215-
Namespace: space,
217+
Namespace: namespace,
216218
Params: map[string]interface{}{
217219
"param1": "some-params",
218220
"my_url": "http://localhost:8080",
@@ -280,7 +282,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
280282
},
281283
APMServiceName: "APMServiceName",
282284
TimeoutSeconds: 42,
283-
Namespace: space,
285+
Namespace: namespace,
284286
Params: map[string]interface{}{
285287
"param1": "some-params",
286288
"my_url": "http://localhost:8080",
@@ -338,7 +340,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() {
338340
},
339341
APMServiceName: "APMServiceName",
340342
TimeoutSeconds: 42,
341-
Namespace: space,
343+
Namespace: namespace,
342344
Params: map[string]interface{}{
343345
"param1": "some-params",
344346
"my_url": "http://localhost:8080",
@@ -424,11 +426,11 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsPrivateLocationAPI() {
424426

425427
for _, n := range spaces {
426428
testUuid := uuid.New().String()
427-
namespace := n
429+
space_id := n
428430
pAPI := s.API.KibanaSynthetics.PrivateLocation
429431

430432
s.Run(fmt.Sprintf("TestKibanaSyntheticsPrivateLocationAPI - %s", n), func() {
431-
testWithPolicy(s.T(), s.client, namespace, func(policyId string) {
433+
testWithPolicy(s.T(), s.client, space_id, func(policyId string) {
432434

433435
cfg := PrivateLocationConfig{
434436
Label: fmt.Sprintf("TestKibanaSyntheticsPrivateLocationAPI-%s", testUuid),

0 commit comments

Comments
 (0)