Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
fix(grafana): fixed all metrics and dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
stebenz committed Jan 8, 2020
1 parent 5805c15 commit 27c9c0a
Show file tree
Hide file tree
Showing 35 changed files with 4,988 additions and 16,388 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/toolset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
type ToolsetSpec struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
KubeVersion string `json:"kubeVersion,omitempty" yaml:"kubeVersion"`
PrometheusOperator *PrometheusOperator `json:"prometheus-operator,omitempty" yaml:"prometheus-operator"`
LoggingOperator *LoggingOperator `json:"logging-operator,omitempty" yaml:"logging-operator"`
PrometheusNodeExporter *PrometheusNodeExporter `json:"prometheus-node-exporter,omitempty" yaml:"prometheus-node-exporter"`
Expand Down
22 changes: 10 additions & 12 deletions internal/app/v1beta1/crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,24 @@ func (c *Crd) ReconcileApplications(overlay, toolsDirectoryPath string, toolsetC
}
}

conf, datasource, err := c.ScrapeMetricsCrdsConfig(toolsetCRDSpec)
promConf, datasourceURL, err := c.ScrapeMetricsCrdsConfig(toolsetCRDSpec)
if err != nil {
return err
}
if conf != nil {
if err := c.applications.Prometheus.Reconcile(overlay, toolsetCRDSpec.Namespace, c.helm, conf); err != nil {
if promConf != nil {
if err := c.applications.Prometheus.Reconcile(overlay, toolsetCRDSpec.Namespace, c.helm, promConf); err != nil {
return err
}
}

toolsetCRDSpec.Grafana.Datasources = append(toolsetCRDSpec.Grafana.Datasources, &toolsetsv1beta1.Datasource{
Name: "prometheus",
Type: "prometheus",
Url: datasource,
Access: "proxy",
})

toolsetCRDSpec.Grafana.DashboardProviders = c.GetGrafanaDashboards(filepath.Join(toolsDirectoryPath, "toolsets", toolsetCRDSpec.Name, "dashboards"), toolsetCRDSpec)
if toolsetCRDSpec.Grafana != nil {
if err := c.applications.Grafana.Reconcile(overlay, toolsetCRDSpec.Namespace, c.helm, toolsetCRDSpec.Grafana); err != nil {
dashboardsFolder := filepath.Join(toolsDirectoryPath, "toolsets", toolsetCRDSpec.Name, "dashboards")
grafanaConfig := c.GetGrafanaConfig(dashboardsFolder, toolsetCRDSpec)
if promConf != nil {
grafanaConfig.AddDatasourceURL("prometheus", "prometheus", datasourceURL)
}

if err := c.applications.Grafana.Reconcile(overlay, toolsetCRDSpec.Namespace, c.helm, grafanaConfig); err != nil {
return err
}
}
Expand Down
53 changes: 0 additions & 53 deletions internal/app/v1beta1/crd/dashboards.go

This file was deleted.

64 changes: 64 additions & 0 deletions internal/app/v1beta1/crd/grafana.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package crd

import (
"path/filepath"

toolsetsv1beta1 "github.com/caos/boom/api/v1beta1"
"github.com/caos/boom/internal/app/v1beta1/crd/grafana"
)

var orgID = 0

func (c *Crd) GetGrafanaConfig(dashboardsfolder string, toolsetCRDSpec *toolsetsv1beta1.ToolsetSpec) *grafana.Config {
providers := getGrafanaDashboards(dashboardsfolder, toolsetCRDSpec)
conf := grafana.NewConfig(toolsetCRDSpec.KubeVersion, toolsetCRDSpec.Grafana)

for _, provider := range providers {
conf.AddDashboardProvider(provider)
}
return conf
}

func getGrafanaDashboards(dashboardsfolder string, toolsetCRDSpec *toolsetsv1beta1.ToolsetSpec) []*grafana.ConfigProvider {
providers := make([]*grafana.ConfigProvider, 0)
if toolsetCRDSpec.Ambassador != nil && toolsetCRDSpec.Ambassador.Deploy {
provider := &grafana.ConfigProvider{
ConfigMaps: []string{
"grafana-dashboard-ambassador-envoy-global",
"grafana-dashboard-ambassador-envoy-ingress",
"grafana-dashboard-ambassador-envoy-service",
},
Folder: filepath.Join(dashboardsfolder, "ambassador"),
}
providers = append(providers, provider)
}
if toolsetCRDSpec.Argocd != nil && toolsetCRDSpec.Argocd.Deploy {
provider := &grafana.ConfigProvider{
ConfigMaps: []string{
"grafana-dashboard-argocd",
},
Folder: filepath.Join(dashboardsfolder, "argocd"),
}
providers = append(providers, provider)
}

if toolsetCRDSpec.PrometheusNodeExporter != nil && toolsetCRDSpec.PrometheusNodeExporter.Deploy {
provider := &grafana.ConfigProvider{
ConfigMaps: []string{
"grafana-dashboard-node-cluster-rsrc-use",
"grafana-dashboard-node-rsrc-use",
},
Folder: filepath.Join(dashboardsfolder, "prometheusnodeexporter"),
}
providers = append(providers, provider)
}

// provider := &grafana.ConfigProvider{
// ConfigMaps: []string{
// "grafana-dashboard-kubelet",
// },
// Folder: filepath.Join(dashboardsfolder, "kubelet"),
// }
// providers = append(providers, provider)
return providers
}
Loading

0 comments on commit 27c9c0a

Please sign in to comment.