Skip to content

Commit 92c2528

Browse files
authored
[Documentation] Refactor metrics (Part 1) (#1019)
1 parent 2c59705 commit 92c2528

24 files changed

+997
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- (Feature) Change DBServer Cleanup Logic
2525
- (Feature) Set Logger format
2626
- (Bugfix) Ensure Wait actions to be present after AddMember
27+
- (Documentation) Refactor metrics (Part 1)
2728

2829
## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
2930
- (Bugfix) Fix arangosync members state inspection

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,8 @@ check-community:
531531

532532
_check:
533533
@$(MAKE) fmt license-verify linter run-unit-tests bin
534+
535+
generate-documentation: generate-go-documentation fmt
536+
537+
generate-go-documentation:
538+
ROOT=$(ROOT) go test --count=1 "$(REPOPATH)/internal/..."

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
- [Documentation](https://www.arangodb.com/docs/stable/deployment-kubernetes.html)
55
- [Design documents](./design/README.md)
66
- [Providers](./providers/README.md)
7+
8+
9+
# ArangoDB Kubernetes Operator Generated Documentation
10+
- [ArangoDB Operator Metrics & Alerts](./generated/metrics/README.md)

docs/generated/metrics/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ArangoDB Operator Metrics
2+
3+
## List
4+
5+
| Name | Namespace | Group | Type | Description |
6+
|:-------------------------------------------------------------------------:|:-----------------:|:------:|:-----:|:-------------------------------------------|
7+
| [arangodb_operator_agency_errors](./arangodb_operator_agency_errors.md) | arangodb_operator | agency | Count | Current count of agency cache fetch errors |
8+
| [arangodb_operator_agency_fetches](./arangodb_operator_agency_fetches.md) | arangodb_operator | agency | Count | Current count of agency cache fetches |
9+
| [arangodb_operator_agency_index](./arangodb_operator_agency_index.md) | arangodb_operator | agency | Gauge | Current index of the agency cache |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# arangodb_operator_agency_errors (Count)
2+
3+
## Description
4+
5+
Current count of agency cache fetch errors
6+
7+
## Labels
8+
9+
| Label | Description |
10+
|:---------:|:---------------------|
11+
| namespace | Deployment Namespace |
12+
| name | Deployment Name |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# arangodb_operator_agency_fetches (Count)
2+
3+
## Description
4+
5+
Current count of agency cache fetches
6+
7+
## Labels
8+
9+
| Label | Description |
10+
|:---------:|:---------------------|
11+
| namespace | Deployment Namespace |
12+
| name | Deployment Name |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# arangodb_operator_agency_index (Gauge)
2+
3+
## Description
4+
5+
Current index of the agency cache
6+
7+
## Labels
8+
9+
| Label | Description |
10+
|:---------:|:---------------------|
11+
| namespace | Deployment Namespace |
12+
| name | Deployment Name |

internal/md/column.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 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 md
22+
23+
import "k8s.io/apimachinery/pkg/util/uuid"
24+
25+
type ColumnAlign int
26+
27+
const (
28+
ColumnRightAlign ColumnAlign = iota
29+
ColumnCenterAlign
30+
ColumnLeftAlign
31+
)
32+
33+
type Columns []Column
34+
35+
func (c Columns) Get(id string) (Column, bool) {
36+
for _, z := range c {
37+
if z.ID() == id {
38+
return z, true
39+
}
40+
}
41+
42+
return nil, false
43+
}
44+
45+
type Column interface {
46+
Name() string
47+
Align() ColumnAlign
48+
49+
ID() string
50+
}
51+
52+
func NewColumn(name string, align ColumnAlign) Column {
53+
return column{
54+
name: name,
55+
id: string(uuid.NewUUID()),
56+
align: align,
57+
}
58+
}
59+
60+
type column struct {
61+
name string
62+
id string
63+
align ColumnAlign
64+
}
65+
66+
func (c column) ID() string {
67+
return c.id
68+
}
69+
70+
func (c column) Name() string {
71+
return c.name
72+
}
73+
74+
func (c column) Align() ColumnAlign {
75+
return c.align
76+
}

internal/md/row.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 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 md

internal/md/table.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 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 md
22+
23+
import (
24+
"sync"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
27+
)
28+
29+
func NewTable(columns ...Column) Table {
30+
return &table{
31+
columns: columns,
32+
}
33+
}
34+
35+
type Table interface {
36+
Render() string
37+
38+
AddRow(in map[Column]string) error
39+
}
40+
41+
type table struct {
42+
lock sync.Mutex
43+
44+
columns Columns
45+
rows []map[string]string
46+
}
47+
48+
func (t *table) AddRow(in map[Column]string) error {
49+
t.lock.Lock()
50+
defer t.lock.Unlock()
51+
52+
r := map[string]string{}
53+
54+
for k, v := range in {
55+
if _, ok := t.columns.Get(k.ID()); !ok {
56+
return errors.Newf("Column not found")
57+
}
58+
59+
r[k.ID()] = v
60+
}
61+
62+
t.rows = append(t.rows, r)
63+
64+
return nil
65+
}
66+
67+
func (t *table) fillString(base, filler string, align ColumnAlign, size int) string {
68+
for len(base) < size {
69+
switch align {
70+
case ColumnLeftAlign:
71+
base += filler
72+
case ColumnRightAlign:
73+
base = filler + base
74+
case ColumnCenterAlign:
75+
base += filler
76+
if len(base) < size {
77+
base = filler + base
78+
}
79+
}
80+
}
81+
82+
return base
83+
}
84+
85+
func (t *table) Render() string {
86+
t.lock.Lock()
87+
defer t.lock.Unlock()
88+
89+
ks := map[string]int{}
90+
91+
for _, c := range t.columns {
92+
ks[c.ID()] = len(c.Name())
93+
}
94+
95+
for _, r := range t.rows {
96+
for _, c := range t.columns {
97+
if q := len(r[c.ID()]); q > ks[c.ID()] {
98+
ks[c.ID()] = q
99+
}
100+
}
101+
}
102+
103+
buff := ""
104+
105+
buff += "|"
106+
107+
for _, c := range t.columns {
108+
buff += " "
109+
buff += t.fillString(c.Name(), " ", c.Align(), ks[c.ID()])
110+
buff += " |"
111+
}
112+
buff += "\n|"
113+
114+
for _, c := range t.columns {
115+
switch c.Align() {
116+
case ColumnLeftAlign, ColumnCenterAlign:
117+
buff += ":"
118+
default:
119+
buff += "-"
120+
}
121+
122+
buff += t.fillString("", "-", ColumnLeftAlign, ks[c.ID()])
123+
switch c.Align() {
124+
case ColumnRightAlign, ColumnCenterAlign:
125+
buff += ":"
126+
default:
127+
buff += "-"
128+
}
129+
buff += "|"
130+
}
131+
buff += "\n"
132+
133+
for _, r := range t.rows {
134+
buff += "|"
135+
136+
for _, c := range t.columns {
137+
buff += " "
138+
buff += t.fillString(r[c.ID()], " ", c.Align(), ks[c.ID()])
139+
buff += " |"
140+
}
141+
buff += "\n"
142+
}
143+
144+
return buff
145+
}

0 commit comments

Comments
 (0)