|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + |
| 20 | +package test |
| 21 | + |
| 22 | +import ( |
| 23 | + "context" |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/arangodb/go-driver" |
| 27 | + |
| 28 | + "github.com/stretchr/testify/require" |
| 29 | +) |
| 30 | + |
| 31 | +// TestGetServerMetrics tests if Client.Metrics works at all |
| 32 | +func TestGetServerMetrics(t *testing.T) { |
| 33 | + c := createClientFromEnv(t, true) |
| 34 | + ctx := context.Background() |
| 35 | + skipBelowVersion(c, "3.8", t) |
| 36 | + |
| 37 | + metrics, err := c.Metrics(ctx) |
| 38 | + require.NoError(t, err) |
| 39 | + require.Contains(t, string(metrics), "arangodb_client_connection_statistics_total_time") |
| 40 | +} |
| 41 | + |
| 42 | +// TestGetServerMetricsForSingleServer tests if Client.MetricsForSingleServer works at all |
| 43 | +func TestGetServerMetricsForSingleServer(t *testing.T) { |
| 44 | + c := createClientFromEnv(t, true) |
| 45 | + ctx := context.Background() |
| 46 | + skipBelowVersion(c, "3.8", t) |
| 47 | + skipNoCluster(c, t) |
| 48 | + |
| 49 | + cl, err := c.Cluster(ctx) |
| 50 | + require.NoError(t, err) |
| 51 | + |
| 52 | + h, err := cl.Health(ctx) |
| 53 | + require.NoError(t, err) |
| 54 | + |
| 55 | + for id, sh := range h.Health { |
| 56 | + if sh.Role == driver.ServerRoleDBServer || sh.Role == driver.ServerRoleCoordinator { |
| 57 | + metrics, err := c.MetricsForSingleServer(ctx, string(id)) |
| 58 | + require.NoError(t, err) |
| 59 | + require.Contains(t, string(metrics), "arangodb_client_connection_statistics_total_time") |
| 60 | + require.Contains(t, string(metrics), sh.ShortName) |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments