Skip to content

Commit 266ca35

Browse files
Allow tcp:// and ssl:// protocols in endpoints for members (#1423)
1 parent 331db7c commit 266ca35

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) Fix make manifests-crd-file command
5+
- (Improvement) Allow tcp:// and ssl:// protocols in endpoints for members
56

67
## [1.2.33](https://github.com/arangodb/kube-arangodb/tree/1.2.33) (2023-09-27)
78
- (Maintenance) Bump golang.org/x/net to v0.13.0

pkg/exporter/monitor.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"time"
3535

3636
"github.com/arangodb/go-driver"
37+
"github.com/arangodb/go-driver/util"
3738

3839
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
3940
"github.com/arangodb/kube-arangodb/pkg/logging"
@@ -51,7 +52,7 @@ var logger = logging.Global().RegisterAndGetLogger("monitor", logging.Info)
5152
var currentMembersStatus atomic.Value
5253

5354
func NewMonitor(arangodbEndpoint string, auth Authentication, sslVerify bool, timeout time.Duration) *monitor {
54-
uri, err := setPath(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint)
55+
uri, err := prepareEndpointURL(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint)
5556
if err != nil {
5657
logger.Err(err).Error("Fatal")
5758
os.Exit(1)
@@ -75,14 +76,14 @@ func (m monitor) UpdateMonitorStatus(ctx context.Context) {
7576

7677
health, err := m.GetClusterHealth()
7778
if err != nil {
78-
logger.Err(err).Error("GetClusterHealth error")
79+
logger.Err(err).Info("GetClusterHealth error")
7980
sleep = failRefreshInterval
8081
} else {
8182
var output strings.Builder
8283
for key, value := range health.Health {
8384
entry, err := m.GetMemberStatus(key, value)
8485
if err != nil {
85-
logger.Err(err).Error("GetMemberStatus error")
86+
logger.Err(err).Info("GetMemberStatus error")
8687
sleep = failRefreshInterval
8788
}
8889
output.WriteString(entry)
@@ -134,7 +135,7 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
134135
return result, err
135136
}
136137

137-
req.URL, err = setPath(member.Endpoint, shared.ArangoExporterStatusEndpoint)
138+
req.URL, err = prepareEndpointURL(member.Endpoint, shared.ArangoExporterStatusEndpoint)
138139
if err != nil {
139140
return result, err
140141
}
@@ -155,7 +156,9 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
155156
return fmt.Sprintf(monitorMetricTemplate, member.Role, id, 1), nil
156157
}
157158

158-
func setPath(uri, uriPath string) (*url.URL, error) {
159+
func prepareEndpointURL(uri, uriPath string) (*url.URL, error) {
160+
uri = util.FixupEndpointURLScheme(uri)
161+
159162
u, err := url.Parse(uri)
160163
if err != nil {
161164
return u, err
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -18,23 +18,27 @@
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
2020

21-
package arangod
21+
package exporter
2222

23-
import "net/url"
23+
import (
24+
"testing"
2425

25-
// IsSameEndpoint returns true when the 2 given endpoints
26-
// refer to the same server.
27-
func IsSameEndpoint_(a, b string) bool {
28-
if a == b {
29-
return true
30-
}
31-
ua, err := url.Parse(a)
32-
if err != nil {
33-
return false
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
func Test_prepareEndpointURL(t *testing.T) {
30+
tcs := []struct {
31+
url, path, expected string
32+
}{
33+
{"http://some-host", "health", "http://some-host/health"},
34+
{"https://some-host", "health", "https://some-host/health"},
35+
{"tcp://some-host", "health", "http://some-host/health"},
36+
{"ssl://some-host", "health", "https://some-host/health"},
3437
}
35-
ub, err := url.Parse(b)
36-
if err != nil {
37-
return false
38+
39+
for i, tc := range tcs {
40+
u, err := prepareEndpointURL(tc.url, tc.path)
41+
require.NoErrorf(t, err, "case %d", i)
42+
require.Equalf(t, tc.expected, u.String(), "case %d", i)
3843
}
39-
return ua.Hostname() == ub.Hostname()
4044
}

0 commit comments

Comments
 (0)