Skip to content
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 @@ -24,6 +24,7 @@
- (Feature) Change DBServer Cleanup Logic
- (Feature) Set Logger format
- (Bugfix) Ensure Wait actions to be present after AddMember
- (Documentation) Refactor metrics (Part 1)

## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
- (Bugfix) Fix arangosync members state inspection
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,8 @@ check-community:

_check:
@$(MAKE) fmt license-verify linter run-unit-tests bin

generate-documentation: generate-go-documentation fmt

generate-go-documentation:
ROOT=$(ROOT) go test --count=1 "$(REPOPATH)/internal/..."
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
- [Documentation](https://www.arangodb.com/docs/stable/deployment-kubernetes.html)
- [Design documents](./design/README.md)
- [Providers](./providers/README.md)


# ArangoDB Kubernetes Operator Generated Documentation
- [ArangoDB Operator Metrics & Alerts](./generated/metrics/README.md)
9 changes: 9 additions & 0 deletions docs/generated/metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ArangoDB Operator Metrics

## List

| Name | Namespace | Group | Type | Description |
|:-------------------------------------------------------------------------:|:-----------------:|:------:|:-----:|:-------------------------------------------|
| [arangodb_operator_agency_errors](./arangodb_operator_agency_errors.md) | arangodb_operator | agency | Count | Current count of agency cache fetch errors |
| [arangodb_operator_agency_fetches](./arangodb_operator_agency_fetches.md) | arangodb_operator | agency | Count | Current count of agency cache fetches |
| [arangodb_operator_agency_index](./arangodb_operator_agency_index.md) | arangodb_operator | agency | Gauge | Current index of the agency cache |
12 changes: 12 additions & 0 deletions docs/generated/metrics/arangodb_operator_agency_errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# arangodb_operator_agency_errors (Count)

## Description

Current count of agency cache fetch errors

## Labels

| Label | Description |
|:---------:|:---------------------|
| namespace | Deployment Namespace |
| name | Deployment Name |
12 changes: 12 additions & 0 deletions docs/generated/metrics/arangodb_operator_agency_fetches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# arangodb_operator_agency_fetches (Count)

## Description

Current count of agency cache fetches

## Labels

| Label | Description |
|:---------:|:---------------------|
| namespace | Deployment Namespace |
| name | Deployment Name |
12 changes: 12 additions & 0 deletions docs/generated/metrics/arangodb_operator_agency_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# arangodb_operator_agency_index (Gauge)

## Description

Current index of the agency cache

## Labels

| Label | Description |
|:---------:|:---------------------|
| namespace | Deployment Namespace |
| name | Deployment Name |
76 changes: 76 additions & 0 deletions internal/md/column.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 md

import "k8s.io/apimachinery/pkg/util/uuid"

type ColumnAlign int

const (
ColumnRightAlign ColumnAlign = iota
ColumnCenterAlign
ColumnLeftAlign
)

type Columns []Column

func (c Columns) Get(id string) (Column, bool) {
for _, z := range c {
if z.ID() == id {
return z, true
}
}

return nil, false
}

type Column interface {
Name() string
Align() ColumnAlign

ID() string
}

func NewColumn(name string, align ColumnAlign) Column {
return column{
name: name,
id: string(uuid.NewUUID()),
align: align,
}
}

type column struct {
name string
id string
align ColumnAlign
}

func (c column) ID() string {
return c.id
}

func (c column) Name() string {
return c.name
}

func (c column) Align() ColumnAlign {
return c.align
}
21 changes: 21 additions & 0 deletions internal/md/row.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 md
145 changes: 145 additions & 0 deletions internal/md/table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 md

import (
"sync"

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

func NewTable(columns ...Column) Table {
return &table{
columns: columns,
}
}

type Table interface {
Render() string

AddRow(in map[Column]string) error
}

type table struct {
lock sync.Mutex

columns Columns
rows []map[string]string
}

func (t *table) AddRow(in map[Column]string) error {
t.lock.Lock()
defer t.lock.Unlock()

r := map[string]string{}

for k, v := range in {
if _, ok := t.columns.Get(k.ID()); !ok {
return errors.Newf("Column not found")
}

r[k.ID()] = v
}

t.rows = append(t.rows, r)

return nil
}

func (t *table) fillString(base, filler string, align ColumnAlign, size int) string {
for len(base) < size {
switch align {
case ColumnLeftAlign:
base += filler
case ColumnRightAlign:
base = filler + base
case ColumnCenterAlign:
base += filler
if len(base) < size {
base = filler + base
}
}
}

return base
}

func (t *table) Render() string {
t.lock.Lock()
defer t.lock.Unlock()

ks := map[string]int{}

for _, c := range t.columns {
ks[c.ID()] = len(c.Name())
}

for _, r := range t.rows {
for _, c := range t.columns {
if q := len(r[c.ID()]); q > ks[c.ID()] {
ks[c.ID()] = q
}
}
}

buff := ""

buff += "|"

for _, c := range t.columns {
buff += " "
buff += t.fillString(c.Name(), " ", c.Align(), ks[c.ID()])
buff += " |"
}
buff += "\n|"

for _, c := range t.columns {
switch c.Align() {
case ColumnLeftAlign, ColumnCenterAlign:
buff += ":"
default:
buff += "-"
}

buff += t.fillString("", "-", ColumnLeftAlign, ks[c.ID()])
switch c.Align() {
case ColumnRightAlign, ColumnCenterAlign:
buff += ":"
default:
buff += "-"
}
buff += "|"
}
buff += "\n"

for _, r := range t.rows {
buff += "|"

for _, c := range t.columns {
buff += " "
buff += t.fillString(r[c.ID()], " ", c.Align(), ks[c.ID()])
buff += " |"
}
buff += "\n"
}

return buff
}
Loading