1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Allow tcp:// and ssl:// protocols in endpoints for members (#1423)

This commit is contained in:
Nikita Vaniasin 2023-09-29 11:27:21 +02:00 committed by GitHub
parent 331db7c852
commit 266ca35b5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 21 deletions

View file

@ -2,6 +2,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Bugfix) Fix make manifests-crd-file command - (Bugfix) Fix make manifests-crd-file command
- (Improvement) Allow tcp:// and ssl:// protocols in endpoints for members
## [1.2.33](https://github.com/arangodb/kube-arangodb/tree/1.2.33) (2023-09-27) ## [1.2.33](https://github.com/arangodb/kube-arangodb/tree/1.2.33) (2023-09-27)
- (Maintenance) Bump golang.org/x/net to v0.13.0 - (Maintenance) Bump golang.org/x/net to v0.13.0

View file

@ -34,6 +34,7 @@ import (
"time" "time"
"github.com/arangodb/go-driver" "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/util"
"github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/logging" "github.com/arangodb/kube-arangodb/pkg/logging"
@ -51,7 +52,7 @@ var logger = logging.Global().RegisterAndGetLogger("monitor", logging.Info)
var currentMembersStatus atomic.Value var currentMembersStatus atomic.Value
func NewMonitor(arangodbEndpoint string, auth Authentication, sslVerify bool, timeout time.Duration) *monitor { func NewMonitor(arangodbEndpoint string, auth Authentication, sslVerify bool, timeout time.Duration) *monitor {
uri, err := setPath(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint) uri, err := prepareEndpointURL(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint)
if err != nil { if err != nil {
logger.Err(err).Error("Fatal") logger.Err(err).Error("Fatal")
os.Exit(1) os.Exit(1)
@ -75,14 +76,14 @@ func (m monitor) UpdateMonitorStatus(ctx context.Context) {
health, err := m.GetClusterHealth() health, err := m.GetClusterHealth()
if err != nil { if err != nil {
logger.Err(err).Error("GetClusterHealth error") logger.Err(err).Info("GetClusterHealth error")
sleep = failRefreshInterval sleep = failRefreshInterval
} else { } else {
var output strings.Builder var output strings.Builder
for key, value := range health.Health { for key, value := range health.Health {
entry, err := m.GetMemberStatus(key, value) entry, err := m.GetMemberStatus(key, value)
if err != nil { if err != nil {
logger.Err(err).Error("GetMemberStatus error") logger.Err(err).Info("GetMemberStatus error")
sleep = failRefreshInterval sleep = failRefreshInterval
} }
output.WriteString(entry) output.WriteString(entry)
@ -134,7 +135,7 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
return result, err return result, err
} }
req.URL, err = setPath(member.Endpoint, shared.ArangoExporterStatusEndpoint) req.URL, err = prepareEndpointURL(member.Endpoint, shared.ArangoExporterStatusEndpoint)
if err != nil { if err != nil {
return result, err return result, err
} }
@ -155,7 +156,9 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
return fmt.Sprintf(monitorMetricTemplate, member.Role, id, 1), nil return fmt.Sprintf(monitorMetricTemplate, member.Role, id, 1), nil
} }
func setPath(uri, uriPath string) (*url.URL, error) { func prepareEndpointURL(uri, uriPath string) (*url.URL, error) {
uri = util.FixupEndpointURLScheme(uri)
u, err := url.Parse(uri) u, err := url.Parse(uri)
if err != nil { if err != nil {
return u, err return u, err

View file

@ -1,7 +1,7 @@
// //
// DISCLAIMER // DISCLAIMER
// //
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany // Copyright 2023 ArangoDB GmbH, Cologne, Germany
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -18,23 +18,27 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany // Copyright holder is ArangoDB GmbH, Cologne, Germany
// //
package arangod package exporter
import "net/url" import (
"testing"
// IsSameEndpoint returns true when the 2 given endpoints "github.com/stretchr/testify/require"
// refer to the same server. )
func IsSameEndpoint_(a, b string) bool {
if a == b { func Test_prepareEndpointURL(t *testing.T) {
return true tcs := []struct {
url, path, expected string
}{
{"http://some-host", "health", "http://some-host/health"},
{"https://some-host", "health", "https://some-host/health"},
{"tcp://some-host", "health", "http://some-host/health"},
{"ssl://some-host", "health", "https://some-host/health"},
} }
ua, err := url.Parse(a)
if err != nil { for i, tc := range tcs {
return false u, err := prepareEndpointURL(tc.url, tc.path)
require.NoErrorf(t, err, "case %d", i)
require.Equalf(t, tc.expected, u.String(), "case %d", i)
} }
ub, err := url.Parse(b)
if err != nil {
return false
}
return ua.Hostname() == ub.Hostname()
} }