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

[Bugfix] Fix internal metrics mode (#1022)

This commit is contained in:
Nikita Vanyasin 2022-07-18 13:52:35 +03:00 committed by GitHub
parent 08604a4f95
commit 330f3de5b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 57 deletions

View file

@ -7,6 +7,8 @@
- (Feature) Remove forgotten ArangoDB jobs during restart - (Feature) Remove forgotten ArangoDB jobs during restart
- (Feature) Add support for managed services - (Feature) Add support for managed services
- (Feature) Recreation member in the high plan - (Feature) Recreation member in the high plan
- (Feature) Add 'crd install' subcommand
- (Bugfix) Fix `internal` metrics mode
## [1.2.14](https://github.com/arangodb/kube-arangodb/tree/1.2.14) (2022-07-14) ## [1.2.14](https://github.com/arangodb/kube-arangodb/tree/1.2.14) (2022-07-14)
- (Feature) Add ArangoSync TLS based rotation - (Feature) Add ArangoSync TLS based rotation
@ -40,7 +42,6 @@
- (Bugfix) Infinite loop fix in ArangoD AsyncClient - (Bugfix) Infinite loop fix in ArangoD AsyncClient
- (Bugfix) Add Panic Handler - (Bugfix) Add Panic Handler
- (Bugfix) Unify yaml packages - (Bugfix) Unify yaml packages
- (Feature) Add 'crd install' subcommand
## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07) ## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
- (Bugfix) Fix arangosync members state inspection - (Bugfix) Fix arangosync members state inspection

View file

@ -28,7 +28,7 @@ In default mode metrics provided by ArangoDB `_admin/metrics` (<=3.7) or `_admin
There are several ways to configure Prometheus to fetch metrics from the ArangoDB Exporter. There are several ways to configure Prometheus to fetch metrics from the ArangoDB Exporter.
Below you're find a sample Prometheus configuration file that can be used to fetch Below you will find a sample Prometheus configuration file that can be used to fetch
metrics from an ArangoDB exporter listening on localhost port 9101 (without TLS). metrics from an ArangoDB exporter listening on localhost port 9101 (without TLS).
```yaml ```yaml

View file

@ -41,7 +41,8 @@ func (m MetricsMode) New() *MetricsMode {
return &m return &m
} }
// deprecated // GetMetricsEndpoint
// Deprecated
func (m MetricsMode) GetMetricsEndpoint() string { func (m MetricsMode) GetMetricsEndpoint() string {
switch m { switch m {
case MetricsModeInternal: case MetricsModeInternal:
@ -52,12 +53,14 @@ func (m MetricsMode) GetMetricsEndpoint() string {
} }
const ( const (
// deprecated // MetricsModeExporter starts sidecar container with
// MetricsModeExporter exporter mode for old exporter type // Deprecated
MetricsModeExporter MetricsMode = "exporter" MetricsModeExporter MetricsMode = "exporter"
// deprecated // MetricsModeSidecar behaves exactly the same as MetricsModeExporter
// Deprecated
MetricsModeSidecar MetricsMode = "sidecar" MetricsModeSidecar MetricsMode = "sidecar"
// deprecated // MetricsModeInternal exposes metrics using ArangoD endpoint
// Deprecated
MetricsModeInternal MetricsMode = "internal" MetricsModeInternal MetricsMode = "internal"
) )
@ -106,14 +109,14 @@ func (s *MetricsSpec) IsEnabled() bool {
return util.BoolOrDefault(s.Enabled, false) return util.BoolOrDefault(s.Enabled, false)
} }
// deprecated
// HasImage returns whether a image was specified or not // HasImage returns whether a image was specified or not
// Deprecated
func (s *MetricsSpec) HasImage() bool { func (s *MetricsSpec) HasImage() bool {
return s.Image != nil return s.Image != nil
} }
// deprecated
// GetImage returns the Image or empty string // GetImage returns the Image or empty string
// Deprecated
func (s *MetricsSpec) GetImage() string { func (s *MetricsSpec) GetImage() string {
return util.StringOrDefault(s.Image) return util.StringOrDefault(s.Image)
} }

View file

@ -41,7 +41,8 @@ func (m MetricsMode) New() *MetricsMode {
return &m return &m
} }
// deprecated // GetMetricsEndpoint
// Deprecated
func (m MetricsMode) GetMetricsEndpoint() string { func (m MetricsMode) GetMetricsEndpoint() string {
switch m { switch m {
case MetricsModeInternal: case MetricsModeInternal:
@ -52,12 +53,14 @@ func (m MetricsMode) GetMetricsEndpoint() string {
} }
const ( const (
// deprecated
// MetricsModeExporter exporter mode for old exporter type // MetricsModeExporter exporter mode for old exporter type
// Deprecated
MetricsModeExporter MetricsMode = "exporter" MetricsModeExporter MetricsMode = "exporter"
// deprecated // MetricsModeSidecar
// Deprecated
MetricsModeSidecar MetricsMode = "sidecar" MetricsModeSidecar MetricsMode = "sidecar"
// deprecated // MetricsModeInternal
// Deprecated
MetricsModeInternal MetricsMode = "internal" MetricsModeInternal MetricsMode = "internal"
) )
@ -106,14 +109,14 @@ func (s *MetricsSpec) IsEnabled() bool {
return util.BoolOrDefault(s.Enabled, false) return util.BoolOrDefault(s.Enabled, false)
} }
// deprecated
// HasImage returns whether a image was specified or not // HasImage returns whether a image was specified or not
// Deprecated
func (s *MetricsSpec) HasImage() bool { func (s *MetricsSpec) HasImage() bool {
return s.Image != nil return s.Image != nil
} }
// deprecated
// GetImage returns the Image or empty string // GetImage returns the Image or empty string
// Deprecated
func (s *MetricsSpec) GetImage() string { func (s *MetricsSpec) GetImage() string {
return util.StringOrDefault(s.Image) return util.StringOrDefault(s.Image)
} }

View file

@ -180,7 +180,6 @@ func TestEnsurePod_Metrics(t *testing.T) {
} }
testCase.createTestPodData(deployment, api.ServerGroupDBServers, firstDBServerStatus) testCase.createTestPodData(deployment, api.ServerGroupDBServers, firstDBServerStatus)
testCase.ExpectedPod.ObjectMeta.Labels[k8sutil.LabelKeyArangoExporter] = testYes
}, },
ExpectedEvent: "member dbserver is created", ExpectedEvent: "member dbserver is created",
ExpectedPod: core.Pod{ ExpectedPod: core.Pod{
@ -212,7 +211,6 @@ func TestEnsurePod_Metrics(t *testing.T) {
ImagePullPolicy: core.PullIfNotPresent, ImagePullPolicy: core.PullIfNotPresent,
SecurityContext: securityContext.NewSecurityContext(), SecurityContext: securityContext.NewSecurityContext(),
}, },
testArangodbInternalExporterContainer(false, false, emptyResources),
}, },
RestartPolicy: core.RestartPolicyNever, RestartPolicy: core.RestartPolicyNever,
TerminationGracePeriodSeconds: &defaultDBServerTerminationTimeout, TerminationGracePeriodSeconds: &defaultDBServerTerminationTimeout,
@ -250,7 +248,6 @@ func TestEnsurePod_Metrics(t *testing.T) {
} }
testCase.createTestPodData(deployment, api.ServerGroupAgents, firstAgentStatus) testCase.createTestPodData(deployment, api.ServerGroupAgents, firstAgentStatus)
testCase.ExpectedPod.ObjectMeta.Labels[k8sutil.LabelKeyArangoExporter] = testYes
}, },
ExpectedEvent: "member agent is created", ExpectedEvent: "member agent is created",
ExpectedPod: core.Pod{ ExpectedPod: core.Pod{
@ -282,7 +279,6 @@ func TestEnsurePod_Metrics(t *testing.T) {
ImagePullPolicy: core.PullIfNotPresent, ImagePullPolicy: core.PullIfNotPresent,
SecurityContext: securityContext.NewSecurityContext(), SecurityContext: securityContext.NewSecurityContext(),
}, },
testArangodbInternalExporterContainer(false, false, emptyResources),
}, },
RestartPolicy: core.RestartPolicyNever, RestartPolicy: core.RestartPolicyNever,
TerminationGracePeriodSeconds: &defaultAgentTerminationTimeout, TerminationGracePeriodSeconds: &defaultAgentTerminationTimeout,

View file

@ -21,8 +21,6 @@ package resources
import ( import (
"path/filepath" "path/filepath"
core "k8s.io/api/core/v1"
"github.com/arangodb/go-driver" "github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@ -32,34 +30,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
) )
// ArangodbExporterContainer creates metrics container
func ArangodbExporterContainer(image string, args []string, livenessProbe *probes.HTTPProbeConfig,
resources core.ResourceRequirements, securityContext *core.SecurityContext,
spec api.DeploymentSpec) core.Container {
c := core.Container{
Name: shared.ExporterContainerName,
Image: image,
Command: append([]string{"/app/arangodb-exporter"}, args...),
Ports: []core.ContainerPort{
{
Name: "exporter",
ContainerPort: int32(spec.Metrics.GetPort()),
Protocol: core.ProtocolTCP,
},
},
Resources: k8sutil.ExtractPodResourceRequirement(resources),
ImagePullPolicy: core.PullIfNotPresent,
SecurityContext: securityContext,
}
if livenessProbe != nil {
c.LivenessProbe = livenessProbe.Create()
}
return c
}
func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGroupSpec, version driver.Version) []string { func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGroupSpec, version driver.Version) []string {
tokenpath := filepath.Join(shared.ExporterJWTVolumeMountDir, constants.SecretKeyToken) tokenpath := filepath.Join(shared.ExporterJWTVolumeMountDir, constants.SecretKeyToken)
options := k8sutil.CreateOptionPairs(64) options := k8sutil.CreateOptionPairs(64)
@ -68,10 +38,7 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
options.Add("--arangodb.jwt-file", tokenpath) options.Add("--arangodb.jwt-file", tokenpath)
} }
path := shared.ArangoExporterInternalEndpoint path := getArangoExporterInternalEndpoint(version)
if version.CompareTo("3.8.0") >= 0 {
path = shared.ArangoExporterInternalEndpointV2
}
if port := groupSpec.InternalPort; port == nil { if port := groupSpec.InternalPort; port == nil {
scheme := "http" scheme := "http"
@ -95,6 +62,14 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
return options.Sort().AsArgs() return options.Sort().AsArgs()
} }
func getArangoExporterInternalEndpoint(version driver.Version) string {
path := shared.ArangoExporterInternalEndpoint
if version.CompareTo("3.8.0") >= 0 {
path = shared.ArangoExporterInternalEndpointV2
}
return path
}
func createExporterLivenessProbe(isSecure bool) *probes.HTTPProbeConfig { func createExporterLivenessProbe(isSecure bool) *probes.HTTPProbeConfig {
probeCfg := &probes.HTTPProbeConfig{ probeCfg := &probes.HTTPProbeConfig{
LocalPath: "/", LocalPath: "/",

View file

@ -344,7 +344,7 @@ func (m *MemberArangoDPod) GetServiceAccountName() string {
} }
func (m *MemberArangoDPod) GetSidecars(pod *core.Pod) error { func (m *MemberArangoDPod) GetSidecars(pod *core.Pod) error {
if m.spec.Metrics.IsEnabled() { if m.spec.Metrics.IsEnabled() && m.spec.Metrics.Mode.Get() != api.MetricsModeInternal {
var c *core.Container var c *core.Container
pod.Labels[k8sutil.LabelKeyArangoExporter] = "yes" pod.Labels[k8sutil.LabelKeyArangoExporter] = "yes"

View file

@ -31,7 +31,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/apis/deployment" "github.com/arangodb/kube-arangodb/pkg/apis/deployment"
deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/globals"
@ -95,7 +94,9 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) {
endpoint.BearerTokenSecret.Name = *spec.Metrics.Authentication.JWTTokenSecretName endpoint.BearerTokenSecret.Name = *spec.Metrics.Authentication.JWTTokenSecretName
endpoint.BearerTokenSecret.Key = constants.SecretKeyToken endpoint.BearerTokenSecret.Key = constants.SecretKeyToken
endpoint.Path = shared.ArangoExporterInternalEndpoint
version := r.context.GetMembersState().State().Version.Version
endpoint.Path = getArangoExporterInternalEndpoint(version)
return coreosv1.ServiceMonitorSpec{ return coreosv1.ServiceMonitorSpec{
JobLabel: "k8s-app", JobLabel: "k8s-app",

View file

@ -34,7 +34,7 @@ const (
LabelKeyApp = "app" LabelKeyApp = "app"
// LabelKeyRole is the key of the label used to store the role of the resource in // LabelKeyRole is the key of the label used to store the role of the resource in
LabelKeyRole = "role" LabelKeyRole = "role"
// LabelKeyArangoExporter is the key of the label used to indicate that a exporter is present // LabelKeyArangoExporter is the key of the label used to indicate that an exporter is present
LabelKeyArangoExporter = "arango_exporter" LabelKeyArangoExporter = "arango_exporter"
// LabelKeyArangoMember is the key of the label used to store the ArangoDeployment member ID in // LabelKeyArangoMember is the key of the label used to store the ArangoDeployment member ID in
LabelKeyArangoMember = "deployment.arangodb.com/member" LabelKeyArangoMember = "deployment.arangodb.com/member"