Skip to content

Commit 4790ae7

Browse files
committed
base 1 commit
1 parent 60d2583 commit 4790ae7

File tree

229 files changed

+8794
-3175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+8794
-3175
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 20 deletions
This file was deleted.

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ linters-settings:
4949
- (github.com/goplugin/plugin-common/pkg/logger.SugaredLogger).AssumptionViolationf
5050
- (github.com/goplugin/plugin-common/pkg/logger.SugaredLogger).Tracef
5151
- (github.com/goplugin/plugin-common/pkg/logger.SugaredLogger).Criticalf
52-
errorlint:
53-
# Allow formatting of errors without %w
54-
errorf: false
5552
revive:
5653
confidence: 0.8
5754
rules:

.tool-versions

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
golang 1.21.4
1+
golang 1.22.7
2+
protoc 25.1
3+
protoc-gen-go-grpc 1.3.0
24
golangci-lint 1.55.2
35
mockery 2.43.2

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ require (
3232
github.com/riferrei/srclient v0.5.4
3333
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0
3434
github.com/shopspring/decimal v1.4.0
35-
github.com/goplugin/grpc-proxy v0.1.1 //plugin update changes
3635
//github.com/goplugin/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7
37-
github.com/goplugin/plugin-libocr v0.1.1-beta //plugin update changes
38-
//github.com/goplugin/plugin-libocr v0.0.0-20240419185742-fd3cab206b2c
36+
github.com/goplugin/grpc-proxy v0.1.1 //plugin update changes
37+
//github.com/goplugin/plugin-libocr v0.0.0-20241007185508-adbe57025f12
38+
github.com/goplugin/plugin-libocr v0.1.1 //plugin update changes
3939
github.com/stretchr/testify v1.9.0
4040
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
4141
go.opentelemetry.io/otel v1.28.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
223223
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
224224
github.com/goplugin/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
225225
github.com/goplugin/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
226-
github.com/goplugin/plugin-libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI=
227-
github.com/goplugin/plugin-libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
226+
github.com/goplugin/plugin-libocr v0.0.0-20241007185508-adbe57025f12 h1:NzZGjaqez21I3DU7objl3xExTH4fxYvzTqar8DC6360=
227+
github.com/goplugin/plugin-libocr v0.0.0-20241007185508-adbe57025f12/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
228228
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
229229
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
230230
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

observability-lib/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ build:
33
go build -o observability-lib .
44

55
.PHONY: run
6-
run:
7-
go run main.go
6+
run: build
7+
./observability-lib
88

99
.PHONY: lint
1010
lint:
1111
golangci-lint run
1212

13+
.PHONY: test
1314
test:
1415
go test -v ./...

observability-lib/README.md

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,135 @@
1-
## Observability-lib
1+
# Observability-lib
22

3-
Contains the observability library to build dashboards and alerts
3+
This library enables creating Grafana dashboards and alerts with go code.
4+
5+
It provides abstractions to create grafana resources :
6+
- [Dashboards](https://grafana.com/docs/grafana/latest/dashboards/)
7+
- [Alerts](https://grafana.com/docs/grafana/latest/alerting/)
8+
- [Contact Points](https://grafana.com/docs/grafana/latest/alerting/fundamentals/notifications/contact-points/)
9+
- [Notification Policies](https://grafana.com/docs/grafana/latest/alerting/configure-notifications/create-notification-policy/)
10+
- [Notification Templates](https://grafana.com/docs/grafana/latest/alerting/configure-notifications/template-notifications/create-notification-templates/)
11+
12+
## Folder Structure
13+
14+
The observability-lib is structured as follows:
15+
```shell
16+
observability-lib/
17+
api/ # Grafana HTTP API Client to interact with resources
18+
cmd/ # CLI to interact deploy or generateJSON from dashboards defined in folder below
19+
dashboards/ # Dashboards definitions
20+
grafana/ # grafana-foundations-sdk abstraction to manipulate grafana resources
21+
```
22+
23+
## Documentation
24+
25+
Godoc generated documentation is available [here](https://pkg.go.dev/github.com/goplugin/plugin-common/observability-lib)
26+
27+
## Quickstart
28+
29+
### Creating a dashboard
30+
31+
<details><summary>main.go</summary>
32+
33+
```go
34+
package main
35+
36+
import "github.com/goplugin/plugin-common/observability-lib/grafana"
37+
38+
func main() {
39+
builder := grafana.NewBuilder(&grafana.BuilderOptions{
40+
Name: "Dashboard Name",
41+
Tags: []string{"tags1", "tags2"},
42+
Refresh: "30s",
43+
TimeFrom: "now-30m",
44+
TimeTo: "now",
45+
})
46+
47+
builder.AddVars(grafana.NewQueryVariable(&grafana.QueryVariableOptions{
48+
VariableOption: &grafana.VariableOption{
49+
Label: "Environment",
50+
Name: "env",
51+
},
52+
Datasource: "Prometheus",
53+
Query: `label_values(up, env)`,
54+
}))
55+
56+
builder.AddRow("Summary")
57+
58+
builder.AddPanel(grafana.NewStatPanel(&grafana.StatPanelOptions{
59+
PanelOptions: &grafana.PanelOptions{
60+
Datasource: "Prometheus",
61+
Title: "Uptime",
62+
Description: "instance uptime",
63+
Span: 12,
64+
Height: 4,
65+
Decimals: 2,
66+
Unit: "s",
67+
Query: []grafana.Query{
68+
{
69+
Expr: `uptime_seconds`,
70+
Legend: `{{ pod }}`,
71+
},
72+
},
73+
},
74+
ColorMode: common.BigValueColorModeNone,
75+
TextMode: common.BigValueTextModeValueAndName,
76+
Orientation: common.VizOrientationHorizontal,
77+
}))
78+
79+
db, err := builder.Build()
80+
if err != nil {
81+
return nil, err
82+
}
83+
json, err := db.GenerateJSON()
84+
if err != nil {
85+
return nil, err
86+
}
87+
fmt.Println(string(json))
88+
}
89+
```
90+
</details>
91+
92+
More advanced examples can be found in the [dashboards](./dashboards) folder :
93+
- [DON OCR](./dashboards/atlas-don/component.go)
94+
- [Capabilities](./dashboards/capabilities/component.go)
95+
- [Node General](./dashboards/core-node/component.go)
96+
- [Node Components](./dashboards/core-node-components/component.go)
97+
- [Kubernetes Resources](./dashboards/k8s-resources/component.go)
98+
- [NOP OCR Health](./dashboards/nop-ocr/component.go)
99+
100+
## Cmd Usage
101+
102+
The CLI can be used to :
103+
- Deploy dashboards and alerts to grafana
104+
- Generate JSON from dashboards defined in the `dashboards` folder
105+
106+
`func NewDashboard(props *Props)` in each [dashboards](./dashboards) packages is called from [cmd](./cmd/builder.go) to deploy or generate JSON from the dashboard.
107+
108+
Example to deploy a dashboard to grafana instance using URL and token:
109+
```shell
110+
make build
111+
./observability-lib deploy \
112+
--dashboard-name DashboardName \
113+
--dashboard-folder FolderName \
114+
--grafana-url $GRAFANA_URL \
115+
--grafana-token $GRAFANA_TOKEN \
116+
--type core-node \
117+
--platform kubernetes \
118+
--metrics-datasource Prometheus
119+
```
120+
To see how to get a grafana token you can check this [page](https://grafana.com/docs/grafana/latest/administration/service-accounts/)
121+
122+
Example to generate JSON from a dashboard defined in the `dashboards` folder:
123+
```shell
124+
make build
125+
./observability-lib generate \
126+
--dashboard-name DashboardName \
127+
--type core-node-components \
128+
--platform kubernetes
129+
```
130+
131+
## Makefile Usage
4132

5-
## Usage
6133

7134
To build the observability library, run the following command:
8135

observability-lib/api/notification-template.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,24 @@ func (c *Client) PutNotificationTemplate(notificationTemplate alerting.Notificat
3030

3131
return grafanaResp, resp, nil
3232
}
33+
34+
type DeleteNotificationTemplateResponse struct{}
35+
36+
func (c *Client) DeleteNotificationTemplate(name string) (DeleteNotificationTemplateResponse, *resty.Response, error) {
37+
var grafanaResp DeleteNotificationTemplateResponse
38+
39+
resp, err := c.resty.R().
40+
SetResult(&grafanaResp).
41+
Delete(fmt.Sprintf("/api/v1/provisioning/templates/%s", name))
42+
43+
if err != nil {
44+
return DeleteNotificationTemplateResponse{}, resp, fmt.Errorf("error making API request: %w", err)
45+
}
46+
47+
statusCode := resp.StatusCode()
48+
if statusCode != 200 {
49+
return DeleteNotificationTemplateResponse{}, resp, fmt.Errorf("error deleting notification template, received unexpected status code %d: %s", statusCode, resp.String())
50+
}
51+
52+
return grafanaResp, resp, nil
53+
}

observability-lib/api/rule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (c *Client) PostAlertRule(alertRule alerting.Rule) (PostAlertRuleResponse,
5353

5454
resp, err := c.resty.R().
5555
SetHeader("Content-Type", "application/json").
56+
SetHeader("X-Disable-Provenance", "true").
5657
SetBody(alertRule).
5758
SetResult(&grafanaResp).
5859
Post("/api/v1/provisioning/alert-rules")

observability-lib/atlas-don/platform.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)