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) Add support for managed services
- (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)
- (Feature) Add ArangoSync TLS based rotation
@ -40,7 +42,6 @@
- (Bugfix) Infinite loop fix in ArangoD AsyncClient
- (Bugfix) Add Panic Handler
- (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)
- (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.
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).
```yaml

View file

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

View file

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

View file

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

View file

@ -21,8 +21,6 @@ package resources
import (
"path/filepath"
core "k8s.io/api/core/v1"
"github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@ -32,34 +30,6 @@ import (
"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 {
tokenpath := filepath.Join(shared.ExporterJWTVolumeMountDir, constants.SecretKeyToken)
options := k8sutil.CreateOptionPairs(64)
@ -68,10 +38,7 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
options.Add("--arangodb.jwt-file", tokenpath)
}
path := shared.ArangoExporterInternalEndpoint
if version.CompareTo("3.8.0") >= 0 {
path = shared.ArangoExporterInternalEndpointV2
}
path := getArangoExporterInternalEndpoint(version)
if port := groupSpec.InternalPort; port == nil {
scheme := "http"
@ -95,6 +62,14 @@ func createInternalExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGro
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 {
probeCfg := &probes.HTTPProbeConfig{
LocalPath: "/",

View file

@ -344,7 +344,7 @@ func (m *MemberArangoDPod) GetServiceAccountName() string {
}
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
pod.Labels[k8sutil.LabelKeyArangoExporter] = "yes"

View file

@ -31,7 +31,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
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/errors"
"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.Key = constants.SecretKeyToken
endpoint.Path = shared.ArangoExporterInternalEndpoint
version := r.context.GetMembersState().State().Version.Version
endpoint.Path = getArangoExporterInternalEndpoint(version)
return coreosv1.ServiceMonitorSpec{
JobLabel: "k8s-app",

View file

@ -34,7 +34,7 @@ const (
LabelKeyApp = "app"
// LabelKeyRole is the key of the label used to store the role of the resource in
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"
// LabelKeyArangoMember is the key of the label used to store the ArangoDeployment member ID in
LabelKeyArangoMember = "deployment.arangodb.com/member"