This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
102 lines (85 loc) · 2.84 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package config
import (
"strings"
toolsetslatest "github.com/caos/orbos/internal/operator/boom/api/latest"
lokiinfo "github.com/caos/orbos/internal/operator/boom/application/applications/loki/info"
prometheusinfo "github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/info"
)
var (
DashboardsDirectoryPath string = "../../dashboards"
)
type Datasource struct {
Name string
Type string
Url string
Access string
IsDefault bool
}
type Provider struct {
ConfigMaps []string
Folder string
}
type Config struct {
Deploy bool
Datasources []*Datasource
DashboardProviders []*Provider
Ini map[string]interface{}
}
func New(spec *toolsetslatest.ToolsetSpec) *Config {
dashboardProviders := make([]*Provider, 0)
if spec.Monitoring != nil && spec.Monitoring.DashboardProviders != nil {
for _, provider := range spec.Monitoring.DashboardProviders {
confProvider := &Provider{
ConfigMaps: provider.ConfigMaps,
Folder: provider.Folder,
}
dashboardProviders = append(dashboardProviders, confProvider)
}
}
datasources := make([]*Datasource, 0)
if spec.Monitoring != nil && spec.Monitoring.Datasources != nil {
for _, datasource := range spec.Monitoring.Datasources {
confDatasource := &Datasource{
Name: datasource.Name,
Type: datasource.Type,
Url: datasource.Url,
Access: datasource.Access,
IsDefault: datasource.IsDefault,
}
datasources = append(datasources, confDatasource)
}
}
conf := &Config{
DashboardProviders: dashboardProviders,
Datasources: datasources,
}
if spec.Monitoring != nil {
conf.Deploy = spec.Monitoring.Deploy
}
providers := getGrafanaDashboards(DashboardsDirectoryPath, spec)
for _, provider := range providers {
conf.AddDashboardProvider(provider)
}
if spec.MetricCollection != nil && spec.MetricsPersisting != nil && spec.MetricCollection.Deploy && spec.MetricsPersisting.Deploy {
serviceName := strings.Join([]string{prometheusinfo.GetInstanceName(), "prometheus"}, "-")
datasourceProm := strings.Join([]string{"http://", serviceName, ".", prometheusinfo.GetNamespace(), ":9090"}, "")
conf.AddDatasourceURL(serviceName, "prometheus", datasourceProm)
}
if spec.LogsPersisting != nil && spec.LogsPersisting.Deploy {
serviceName := lokiinfo.GetName().String()
datasourceLoki := strings.Join([]string{"http://", serviceName, ".", lokiinfo.GetNamespace(), ":3100"}, "")
conf.AddDatasourceURL(serviceName, "loki", datasourceLoki)
}
return conf
}
func (c *Config) AddDashboardProvider(provider *Provider) {
c.DashboardProviders = append(c.DashboardProviders, provider)
}
func (c *Config) AddDatasourceURL(name, datatype, url string) {
c.Datasources = append(c.Datasources, &Datasource{
Name: name,
Type: datatype,
Url: url,
Access: "proxy",
})
}