8000 [Feature] Merge ArangoDB Usage Metrics · arangodb/kube-arangodb@6f37ed0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f37ed0

Browse files
committed
[Feature] Merge ArangoDB Usage Metrics
1 parent bc0c654 commit 6f37ed0

18 files changed

+325
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- (Bugfix) Fix Image Error Propagation
99
- (Feature) JobScheduler Coverage
1010
- (Feature) JobScheduler Volumes, Probes, Lifecycle and Ports integration
11+
- (Feature) Merge ArangoDB Usage Metrics
1112

1213
## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
1314
- (Feature) Extract GRPC Server

cmd/exporter.go

Lines changed: 13 additions & 8 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 2016-2024 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.
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/arangodb/kube-arangodb/pkg/exporter"
3434
"github.com/arangodb/kube-arangodb/pkg/util"
35+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3536
)
3637

3738
var (
@@ -43,9 +44,9 @@ var (
4344
exporterInput struct {
4445
listenAddress string
4546

46-
endpoint string
47-
jwtFile string
48-
timeout time.Duration
47+
endpoints []string
48+
jwtFile string
49+
timeout time.Duration
4950

5051
keyfile string
5152
}
@@ -57,7 +58,7 @@ func init() {
5758
f.StringVar(&exporterInput.listenAddress, "server.address", ":9101", "Address the exporter will listen on (IP:port)")
5859
f.StringVar(&exporterInput.keyfile, "ssl.keyfile", "", "File containing TLS certificate used for the metrics server. Format equal to ArangoDB keyfiles")
5960

60-
f.StringVar(&exporterInput.endpoint, "arangodb.endpoint", "http://127.0.0.1:8529", "Endpoint used to reach the ArangoDB server")
61+
f.StringSliceVar(&exporterInput.endpoints, "arangodb.endpoint", []string{"http://127.0.0.1:8529"}, "Endpoints used to reach the ArangoDB server")
6162
f.StringVar(&exporterInput.jwtFile, "arangodb.jwt-file", "", "File containing the JWT for authentication with ArangoDB server")
6263
f.DurationVar(&exporterInput.timeout, "arangodb.timeout", time.Second*15, "Timeout of statistics requests for ArangoDB")
6364

@@ -83,7 +84,11 @@ func onSigterm(f func()) {
8384
}
8485

8586
func cmdExporterCheckE() error {
86-
p, err := exporter.NewPassthru(exporterInput.endpoint, func() (string, error) {
87+
if len(exporterInput.endpoints) < 1 {
88+
return errors.Errorf("Requires at least one ArangoDB Endpoint to be present")
89+
}
90+
91+
p, err := exporter.NewPassthru(func() (string, error) {
8792
if exporterInput.jwtFile == "" {
8893
return "", nil
8994
}
@@ -94,12 +99,12 @@ func cmdExporterCheckE() error {
9499
}
95100

96101
return string(data), nil
97-
}, false, 15*time.Second)
102+
}, false, 15*time.Second, exporterInput.endpoints...)
98103
if err != nil {
99104
return err
100105
}
101106

102-
mon := exporter.NewMonitor(exporterInput.endpoint, func() (string, error) {
107+
mon := exporter.NewMonitor(exporterInput.endpoints[0], func() (string, error) {
103108
if exporterInput.jwtFile == "" {
104109
return "", nil
105110
}

docs/api/ArangoDeployment.V1.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,19 @@ Default Value: `false`
34053405

34063406
***
34073407

3408+
### .spec.metrics.extensions.usageMetrics
3409+
3410+
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/deployment/v1/deployment_metrics_spec_extensions.go#L28)</sup>
3411+
3412+
UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
3413+
3414+
Links:
3415+
* [Documentation](Documentation:https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics)
3416+
3417+
Default Value: `false`
3418+
3419+
***
3420+
34083421
### .spec.metrics.image
34093422

34103423
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/deployment/v1/deployment_metrics_spec.go#L86)</sup>

pkg/apis/deployment/v1/deployment_metrics_spec.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ type MetricsSpec struct {
105105
ServiceMonitor *MetricsServiceMonitorSpec `json:"serviceMonitor,omitempty"`
106106

107107
Port *uint16 `json:"port,omitempty"`
108+
109+
// Extensions keeps the information about Metrics Extensions
110+
Extensions *MetricsSpecExtensions `json:"extensions,omitempty"`
108111
}
109112

110113
func (s *MetricsSpec) IsTLS() bool {
@@ -123,6 +126,14 @@ func (s *MetricsSpec) GetPort() uint16 {
123126
return *s.Port
124127
}
125128

129+
func (s *MetricsSpec) GetExtensions() *MetricsSpecExtensions {
130+
if s == nil || s.Extensions == nil {
131+
return nil
132+
}
133+
134+
return s.Extensions
135+
}
136+
126137
// IsEnabled returns whether metrics are enabled or not
127138
func (s *MetricsSpec) IsEnabled() bool {
128139
return util.TypeOrDefault[bool](s.Enabled, false)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 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+
21+
package v1
22+
23+
// MetricsSpecExtensions defines enabled extensions for MetricsExporter
24+
type MetricsSpecExtensions struct {
25+
// UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
26+
// +doc/default: false
27+
// +doc/link: Documentation:https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics
28+
UsageMetrics *bool `json:"usageMetrics,omitempty"`
29+
}
30+
31+
func (m *MetricsSpecExtensions) GetUsageMetrics() bool {
32+
if m == nil || m.UsageMetrics == nil {
33+
return false
34+
}
35+
36+
return *m.UsageMetrics
37+
}

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ type MetricsSpec struct {
105105
ServiceMonitor *MetricsServiceMonitorSpec `json:"serviceMonitor,omitempty"`
106106

107107
Port *uint16 `json:"port,omitempty"`
108+
109+
// Extensions keeps the information about Metrics Extensions
110+
Extensions *MetricsSpecExtensions `json:"extensions,omitempty"`
108111
}
109112

110113
func (s *MetricsSpec) IsTLS() bool {
@@ -123,6 +126,14 @@ func (s *MetricsSpec) GetPort() uint16 {
123126
return *s.Port
124127
}
125128

129+
func (s *MetricsSpec) GetExtensions() *MetricsSpecExtensions {
130+
if s == nil || s.Extensions == nil {
131+
return nil
132+
}
133+
134+
return s.Extensions
135+
}
136+
126137
// F438 IsEnabled returns whether metrics are enabled or not
127138
func (s *MetricsSpec) IsEnabled() bool {
128139
return util.TypeOrDefault[bool](s.Enabled, false)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 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+
21+
package v2alpha1
22+
23+
// MetricsSpecExtensions defines enabled extensions for MetricsExporter
24+
type MetricsSpecExtensions struct {
25+
// UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
26+
// +doc/default: false
27+
// +doc/link: Documentation:https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics
28+
UsageMetrics *bool `json:"usageMetrics,omitempty"`
29+
}
30+
31+
func (m *MetricsSpecExtensions) GetUsageMetrics() bool {
32+
if m == nil || m.UsageMetrics == nil {
33+
return false
34+
}
35+
36+
return *m.UsageMetrics
37+
}

pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
ArangoExporterClusterHealthEndpoint = "/_admin/cluster/health"
3232
ArangoExporterInternalEndpoint = "/_admin/metrics"
3333
ArangoExporterInternalEndpointV2 = "/_admin/metrics/v2"
34+
ArangoExporterUsageEndpoint = "/_admin/usage-metrics"
3435
ArangoExporterDefaultEndpoint = "/metrics"
3536

3637
ArangoSyncStatusEndpoint = "/_api/version"

pkg/crd/crds/database-deployment.schema.generated.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6917,6 +6917,13 @@ v1:
69176917
Enabled if this is set to `true`, the operator runs a sidecar container for
69186918
every Agent, DB-Server, Coordinator and Single server.
69196919
type: boolean
6920+
extensions:
6921+
description: Extensions keeps the information about Metrics Extensions
6922+
properties:
6923+
usageMetrics:
6924+
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
6925+
type: boolean
6926+
type: object
69206927
image:
69216928
description: Image used for the Metrics Sidecar
69226929
type: string
@@ -20398,6 +20405,13 @@ v1alpha:
2039820405
Enabled if this is set to `true`, the operator runs a sidecar container for
2039920406
every Agent, DB-Server, Coordinator and Single server.
2040020407
type: boolean
20408+
extensions:
20409+
description: Extensions keeps the information about Metrics Extensions
20410+
properties:
20411+
usageMetrics:
20412+
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
20413+
type: boolean
20414+
type: object
2040120415
image:
2040220416
description: Image used for the Metrics Sidecar
2040320417
type: string
@@ -33879,6 +33893,13 @@ v2alpha1:
3387933893
Enabled if this is set to `true`, the operator runs a sidecar container for
3388033894
every Agent, DB-Server, Coordinator and Single server.
3388133895
type: boolean
33896+
extensions:
33897+
description: Extensions keeps the information about Metrics Extensions
33898+
properties:
33899+
usageMetrics:
33900+
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
33901+
type: boolean
33902+
type: object
3388233903
image:
3388333904
description: Image used for the Metrics Sidecar
3388433905
type: string

pkg/deployment/resources/exporter.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
2+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import (
3030
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
3131
)
3232

33-
func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGroupSpec, version driver.Version) []string {
33+
func createInternalExporterArgs(spec api.DeploymentSpec, group api.ServerGroup, groupSpec api.ServerGroupSpec, version driver.Version) []string {
3434
tokenpath := filepath.Join(shared.ExporterJWTVolumeMountDir, constants.SecretKeyToken)
3535
options := k8sutil.CreateOptionPairs(64)
3636

@@ -46,8 +46,14 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
4646
scheme = "https"
4747
}
4848
options.Addf("--arangodb.endpoint", "%s://localhost:%d%s", scheme, groupSpec.GetPort(), path)
49+
if spec.Metrics.GetExtensions().GetUsageMetrics() && group == api.ServerGroupDBServers {
50+
options.Addf("--arangodb.endpoint", "%s://localhost:%d%s", scheme, groupSpec.GetPort(), shared.ArangoExporterUsageEndpoint)
51+
}
4952
} else {
5053
options.Addf("--arangodb.endpoint", "http://localhost:%d%s", *port, path)
54+
if spec.Metrics.GetExtensions().GetUsageMetrics() && group == api.ServerGroupDBServers {
55+
options.Addf("--arangodb.endpoint", "http://localhost:%d%s", groupSpec.GetPort(), shared.ArangoExporterUsageEndpoint)
56+
}
5157
}
5258

5359
keyPath := filepath.Join(shared.TLSKeyfileVolumeMountDir, constants.SecretTLSKeyfile)

pkg/deployment/resources/internal_exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
2+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ func ArangodbInternalExporterContainer(image string, args []string, livenessProb
5050
Command: append([]string{exePath, "exporter"}, args...),
5151
Ports: []core.ContainerPort{
5252
{
53-
Name: "exporter",
53+
Name: shared.ExporterContainerName,
5454
ContainerPort: int32(port),
5555
Protocol: core.ProtocolTCP,
5656
},

0 commit comments

Comments
 (0)
0