Skip to content

[Feature] Merge ArangoDB Usage Metrics #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- (Bugfix) Fix Image Error Propagation
- (Feature) JobScheduler Coverage
- (Feature) JobScheduler Volumes, Probes, Lifecycle and Ports integration
- (Feature) Merge ArangoDB Usage Metrics

## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
- (Feature) Extract GRPC Server
Expand Down
21 changes: 13 additions & 8 deletions cmd/exporter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -32,6 +32,7 @@ import (

"github.com/arangodb/kube-arangodb/pkg/exporter"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

var (
Expand All @@ -43,9 +44,9 @@ var (
exporterInput struct {
listenAddress string

endpoint string
jwtFile string
timeout time.Duration
endpoints []string
jwtFile string
timeout time.Duration

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

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

Expand All @@ -83,7 +84,11 @@ func onSigterm(f func()) {
}

func cmdExporterCheckE() error {
p, err := exporter.NewPassthru(exporterInput.endpoint, func() (string, error) {
if len(exporterInput.endpoints) < 1 {
return errors.Errorf("Requires at least one ArangoDB Endpoint to be present")
}

p, err := exporter.NewPassthru(func() (string, error) {
if exporterInput.jwtFile == "" {
return "", nil
}
Expand All @@ -94,12 +99,12 @@ func cmdExporterCheckE() error {
}

return string(data), nil
}, false, 15*time.Second)
}, false, 15*time.Second, exporterInput.endpoints...)
if err != nil {
return err
}

mon := exporter.NewMonitor(exporterInput.endpoint, func() (string, error) {
mon := exporter.NewMonitor(exporterInput.endpoints[0], func() (string, error) {
if exporterInput.jwtFile == "" {
return "", nil
}
Expand Down
16 changes: 16 additions & 0 deletions docs/api/ArangoDeployment.V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,22 @@ Default Value: `false`

***

### .spec.metrics.extensions.usageMetrics

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

> [!IMPORTANT]
> **UsageMetrics needs to be also enabled via DBServer Arguments**

UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.

Links:
* [Documentation](https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics)

Default Value: `false`

***

### .spec.metrics.image

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/deployment/v1/deployment_metrics_spec.go#L86)</sup>
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/deployment/v1/deployment_metrics_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ type MetricsSpec struct {
ServiceMonitor *MetricsServiceMonitorSpec `json:"serviceMonitor,omitempty"`

Port *uint16 `json:"port,omitempty"`

// Extensions keeps the information about Metrics Extensions
Extensions *MetricsSpecExtensions `json:"extensions,omitempty"`
}

func (s *MetricsSpec) IsTLS() bool {
Expand All @@ -123,6 +126,14 @@ func (s *MetricsSpec) GetPort() uint16 {
return *s.Port
}

func (s *MetricsSpec) GetExtensions() *MetricsSpecExtensions {
if s == nil || s.Extensions == nil {
return nil
}

return s.Extensions
}

// IsEnabled returns whether metrics are enabled or not
func (s *MetricsSpec) IsEnabled() bool {
return util.TypeOrDefault[bool](s.Enabled, false)
Expand Down
38 changes: 38 additions & 0 deletions pkg/apis/deployment/v1/deployment_metrics_spec_extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// DISCLAIMER
//
// Copyright 2024 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 v1

// MetricsSpecExtensions defines enabled extensions for MetricsExporter
type MetricsSpecExtensions struct {
// UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
// +doc/default: false
// +doc/link: Documentation|https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics
// +doc/important: UsageMetrics needs to be also enabled via DBServer Arguments
UsageMetrics *bool `json:"usageMetrics,omitempty"`
}

func (m *MetricsSpecExtensions) GetUsageMetrics() bool {
if m == nil || m.UsageMetrics == nil {
return false
}

return *m.UsageMetrics
}
26 changes: 26 additions & 0 deletions pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ type MetricsSpec struct {
ServiceMonitor *MetricsServiceMonitorSpec `json:"serviceMonitor,omitempty"`

Port *uint16 `json:"port,omitempty"`

// Extensions keeps the information about Metrics Extensions
Extensions *MetricsSpecExtensions `json:"extensions,omitempty"`
}

func (s *MetricsSpec) IsTLS() bool {
Expand All @@ -123,6 +126,14 @@ func (s *MetricsSpec) GetPort() uint16 {
return *s.Port
}

func (s *MetricsSpec) GetExtensions() *MetricsSpecExtensions {
if s == nil || s.Extensions == nil {
return nil
}

return s.Extensions
}

// IsEnabled returns whether metrics are enabled or not
func (s *MetricsSpec) IsEnabled() bool {
return util.TypeOrDefault[bool](s.Enabled, false)
Expand Down
38 changes: 38 additions & 0 deletions pkg/apis/deployment/v2alpha1/deployment_metrics_spec_extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// DISCLAIMER
//
// Copyright 2024 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 v2alpha1

// MetricsSpecExtensions defines enabled extensions for MetricsExporter
type MetricsSpecExtensions struct {
// UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
// +doc/default: false
// +doc/link: Documentation|https://docs.arangodb.com/devel/develop/http-api/monitoring/metrics/#get-usage-metrics
// +doc/important: UsageMetrics needs to be also enabled via DBServer Arguments
UsageMetrics *bool `json:"usageMetrics,omitempty"`
}

func (m *MetricsSpecExtensions) GetUsageMetrics() bool {
if m == nil || m.UsageMetrics == nil {
return false
}

return *m.UsageMetrics
}
26 changes: 26 additions & 0 deletions pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/shared/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
ArangoExporterClusterHealthEndpoint = "/_admin/cluster/health"
ArangoExporterInternalEndpoint = "/_admin/metrics"
ArangoExporterInternalEndpointV2 = "/_admin/metrics/v2"
ArangoExporterUsageEndpoint = "/_admin/usage-metrics"
ArangoExporterDefaultEndpoint = "/metrics"

ArangoSyncStatusEndpoint = "/_api/version"
Expand Down
21 changes: 21 additions & 0 deletions pkg/crd/crds/database-deployment.schema.generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6917,6 +6917,13 @@ v1:
Enabled if this is set to `true`, the operator runs a sidecar container for
every Agent, DB-Server, Coordinator and Single server.
type: boolean
extensions:
description: Extensions keeps the information about Metrics Extensions
properties:
usageMetrics:
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
type: boolean
type: object
image:
description: Image used for the Metrics Sidecar
type: string
Expand Down Expand Up @@ -20398,6 +20405,13 @@ v1alpha:
Enabled if this is set to `true`, the operator runs a sidecar container for
every Agent, DB-Server, Coordinator and Single server.
type: boolean
extensions:
description: Extensions keeps the information about Metrics Extensions
properties:
usageMetrics:
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
type: boolean
type: object
image:
description: Image used for the Metrics Sidecar
type: string
Expand Down Expand Up @@ -33879,6 +33893,13 @@ v2alpha1:
Enabled if this is set to `true`, the operator runs a sidecar container for
every Agent, DB-Server, Coordinator and Single server.
type: boolean
extensions:
description: Extensions keeps the information about Metrics Extensions
properties:
usageMetrics:
description: UsageMetrics enables ArangoDB Usage metrics scrape. Affects only DBServers in the Cluster mode.
type: boolean
type: object
image:
description: Image used for the Metrics Sidecar
type: string
Expand Down
10 changes: 8 additions & 2 deletions pkg/deployment/resources/exporter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -30,7 +30,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
)

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

Expand All @@ -46,8 +46,14 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
scheme = "https"
}
options.Addf("--arangodb.endpoint", "%s://localhost:%d%s", scheme, groupSpec.GetPort(), path)
if spec.Metrics.GetExtensions().GetUsageMetrics() && group == api.ServerGroupDBServers {
options.Addf("--arangodb.endpoint", "%s://localhost:%d%s", scheme, groupSpec.GetPort(), shared.ArangoExporterUsageEndpoint)
}
} else {
options.Addf("--arangodb.endpoint", "http://localhost:%d%s", *port, path)
if spec.Metrics.GetExtensions().GetUsageMetrics() && group == api.ServerGroupDBServers {
options.Addf("--arangodb.endpoint", "http://localhost:%d%s", groupSpec.GetPort(), shared.ArangoExporterUsageEndpoint)
}
}

keyPath := filepath.Join(shared.TLSKeyfileVolumeMountDir, constants.SecretTLSKeyfile)
Expand Down
Loading