Skip to content

Commit

Permalink
Allow tcp:// and ssl:// protocols in endpoints for members
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-vanyasin committed Sep 27, 2023
1 parent 8e055bb commit 123fc9f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log

- (Improvement) Allow tcp:// and ssl:// protocols in endpoints for members

## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Maintenance) Bump golang.org/x/net to v0.13.0
- (Feature) PVCResize action concurrency limit
Expand Down
9 changes: 6 additions & 3 deletions pkg/exporter/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"time"

"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/logging"
Expand All @@ -51,7 +52,7 @@ var logger = logging.Global().RegisterAndGetLogger("monitor", logging.Info)
var currentMembersStatus atomic.Value

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 {
logger.Err(err).Error("Fatal")
os.Exit(1)
Expand Down Expand Up @@ -134,7 +135,7 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
return result, err
}

req.URL, err = setPath(member.Endpoint, shared.ArangoExporterStatusEndpoint)
req.URL, err = prepareEndpointURL(member.Endpoint, shared.ArangoExporterStatusEndpoint)
if err != nil {
return result, err
}
Expand All @@ -155,7 +156,9 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth)
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)
if err != nil {
return u, err
Expand Down
44 changes: 44 additions & 0 deletions pkg/exporter/monitor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package exporter

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_prepareEndpointURL(t *testing.T) {
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"},
}

for i, tc := range tcs {
u, err := prepareEndpointURL(tc.url, tc.path)
require.NoErrorf(t, err, "case %d", i)
require.Equalf(t, tc.expected, u.String(), "case %d", i)
}
}

0 comments on commit 123fc9f

Please sign in to comment.