Skip to content

Commit

Permalink
remove other node exporter references
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrennz committed Sep 23, 2024
1 parent 3d36b11 commit 934dcee
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 292 deletions.
2 changes: 0 additions & 2 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ The `prometheus` section configures Prometheus settings.
| Key | Description | Required | Default Values |
|------------------------------------------|-------------------|----------|----------------|
| kube_state_metrics_service_endpoint | The endpoint for kube-state-metrics service | Mandatory | |
| prometheus_node_exporter_service_endpoint| The endpoint for node-exporter service | Mandatory | |
| configurations | List of one or more configuration files locations for prometheus to validate | Mandatory | |

## Diagnostics
Expand All @@ -76,7 +75,6 @@ The following table describes the available checkers:
| `k8s_version` | Checks the Kubernetes compatability |
| `egress_reachable` | Checks pod can communicate with the Cloudzero API |
| `kube_state_metrics_reachable` | Checks the kubernetes state metrics service is reachable |
| `node_exporter_reachable` | Checks the prometheus node exporter service is reachable |
| `scrape_cfg` | Checks the prometheus configurations exist and contain the necessary scrape configuration |

## Example
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/config/internal/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ cloudzero:

prometheus:
kube_state_metrics_service_endpoint: {{ .KubeStateMetricsURL }}
prometheus_node_exporter_service_endpoint: {{ .PromNodeExporterURL }}
configurations:
- /etc/config/prometheus/configmaps/prometheus.yml

Expand All @@ -33,7 +32,6 @@ diagnostics:
checks:
- k8s_version
- kube_state_metrics_reachable
- node_exporter_reachable
- scrape_cfg
- name: pre-stop
enforce: false
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (
DiagnosticK8sVersion string = "k8s_version"
DiagnosticEgressAccess string = "egress_reachable"
DiagnosticKMS string = "kube_state_metrics_reachable"
DiagnosticNodeExporter string = "node_exporter_reachable"
DiagnosticPrometheusVersion string = "prometheus_version"
DiagnosticScrapeConfig string = "scrape_cfg"
)
Expand All @@ -27,7 +26,7 @@ func IsValidDiagnostic(d string) bool {
d = strings.ToLower(strings.TrimSpace(d))
switch d {
case DiagnosticAPIKey, DiagnosticK8sVersion, DiagnosticEgressAccess,
DiagnosticKMS, DiagnosticNodeExporter, DiagnosticScrapeConfig,
DiagnosticKMS, DiagnosticScrapeConfig,
DiagnosticPrometheusVersion:
return true
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/config/diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ func TestDiagnostics_IsValidDiagnostics(t *testing.T) {
diagnostic: config.DiagnosticKMS,
expected: true,
},
{
name: "DiagnosticNodeExporter",
diagnostic: config.DiagnosticNodeExporter,
expected: true,
},
{
name: "DiagnosticScrapeConfig",
diagnostic: config.DiagnosticScrapeConfig,
Expand Down
1 change: 0 additions & 1 deletion pkg/config/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ const (
ErrNoChartVersionMsg = "missing Chart Version"
ErrNoScrapeConfigLocationMsg = "missing Scrape Config Location"
ErrNoKubeStateMetricsServiceEndpointMsg = "missing Kube State Metrics Service Endpoint"
ErrNoPrometheusNodeExporterServiceEndpointMsg = "missing Prometheus Node Exporter Service Endpoint"
)
8 changes: 0 additions & 8 deletions pkg/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
type Prometheus struct {
Executable string `yaml:"executable" default:"/bin/prometheus" env:"PROMETHEUS_EXECUTABLE" env-description:"Prometheus Executable Path"`
KubeStateMetricsServiceEndpoint string `yaml:"kube_state_metrics_service_endpoint" env:"KMS_EP_URL" required:"true" env-description:"Kube State Metrics Service Endpoint"`
PrometheusNodeExporterServiceEndpoint string `yaml:"prometheus_node_exporter_service_endpoint" env:"NODE_EXPORTER_EP_URL" required:"true" env-description:"Prometheus Node Exporter Service Endpoint"`
Configurations []string `yaml:"configurations"`
}

Expand All @@ -22,13 +21,6 @@ func (s *Prometheus) Validate() error {
return fmt.Errorf("invalid %s", s.KubeStateMetricsServiceEndpoint)
}

if s.PrometheusNodeExporterServiceEndpoint == "" {
return errors.New(ErrNoPrometheusNodeExporterServiceEndpointMsg)
}
if !isValidURL(s.PrometheusNodeExporterServiceEndpoint) {
return fmt.Errorf("URL format invalid: %s", s.PrometheusNodeExporterServiceEndpoint)
}

if len(s.Configurations) == 0 {
s.Configurations = []string{
"/etc/prometheus/prometheus.yml",
Expand Down
103 changes: 46 additions & 57 deletions pkg/config/prometheus_test.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,55 @@
package config_test

import (
"os"
"testing"
"os"
"testing"

"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

func TestPrometheus_Validate(t *testing.T) {
wd, err := os.Getwd()
assert.NoError(t, err)
scrapeConfigFile := wd + "/testdata/prometheus.yml"
tests := []struct {
name string
prom config.Prometheus
expected error
}{
{
name: "ValidPrometheus",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
PrometheusNodeExporterServiceEndpoint: promNodeExporterServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: nil,
},
{
name: "MissingKubeStateMetricsServiceEndpoint",
prom: config.Prometheus{
PrometheusNodeExporterServiceEndpoint: promNodeExporterServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: errors.New(config.ErrNoKubeStateMetricsServiceEndpointMsg),
},
{
name: "MissingPrometheusNodeExporterServiceEndpoint",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: errors.New(config.ErrNoPrometheusNodeExporterServiceEndpointMsg),
},
{
name: "MissingScrapeConfigLocation",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
PrometheusNodeExporterServiceEndpoint: promNodeExporterServiceEndpoint,
},
expected: nil,
},
}
wd, err := os.Getwd()
assert.NoError(t, err)
scrapeConfigFile := wd + "/testdata/prometheus.yml"
tests := []struct {
name string
prom config.Prometheus
expected error
}{
{
name: "ValidPrometheus",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: nil,
},
{
name: "MissingKubeStateMetricsServiceEndpoint",
prom: config.Prometheus{
Configurations: []string{scrapeConfigFile},
},
expected: errors.New(config.ErrNoKubeStateMetricsServiceEndpointMsg),
},
{
name: "MissingScrapeConfigLocation",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
},
expected: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.prom.Validate()
if tt.expected == nil {
assert.NoError(t, err)
return
}
assert.Equal(t, tt.expected.Error(), err.Error())
})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.prom.Validate()
if tt.expected == nil {
assert.NoError(t, err)
return
}
assert.Equal(t, tt.expected.Error(), err.Error())
})
}
}
2 changes: 0 additions & 2 deletions pkg/config/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
apiKey = "my-cloudzero-token"

kmsServiceEndpoint = "http://kube-state-metrics:8080"
promNodeExporterServiceEndpoint = "http://node-exporter:8080"
)

func TestSettings_NewSettings(t *testing.T) {
Expand Down Expand Up @@ -50,7 +49,6 @@ func TestSettings_NewSettings(t *testing.T) {

// verify Prometheus
assert.Equal(t, kmsServiceEndpoint, settings.Prometheus.KubeStateMetricsServiceEndpoint)
assert.Equal(t, promNodeExporterServiceEndpoint, settings.Prometheus.PrometheusNodeExporterServiceEndpoint)
assert.Equal(t, []string{"prometheus.yml"}, settings.Prometheus.Configurations)

// verify Diagnostics
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/testdata/cloudzero-agent-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ cloudzero:

prometheus:
kube_state_metrics_service_endpoint: http://kube-state-metrics:8080
prometheus_node_exporter_service_endpoint: http://node-exporter:8080
configurations:
- prometheus.yml

Expand All @@ -35,7 +34,6 @@ diagnostics:
- k8s_version
- egress_reachable
- kube_state_metrics_reachable
- node_exporter_reachable
- scrape_cfg
- name: pre-stop
enforce: false
Expand Down
1 change: 0 additions & 1 deletion pkg/config/testdata/file.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ LOG_LEVEL=info
LOG_LOCATION=cloudzero-agent-validator.log

KMS_EP_URL='http://cloudzero-agent-kube-state-metrics:8080/'
NODE_EXPORTER_EP_URL='http://node-exporter.monitoring.svc.cluster.local:9100/'
2 changes: 0 additions & 2 deletions pkg/diagnostic/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/egress"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/k8s"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/kms"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/pne"
promcfg "github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/prom/config"
promver "github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/prom/version"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/stage"
Expand Down Expand Up @@ -42,7 +41,6 @@ func NewCatalog(ctx context.Context, c *config.Settings) Registry {
r.add(config.DiagnosticEgressAccess, false, egress.NewProvider(ctx, c))
r.add(config.DiagnosticK8sVersion, false, k8s.NewProvider(ctx, c))
r.add(config.DiagnosticKMS, false, kms.NewProvider(ctx, c))
r.add(config.DiagnosticNodeExporter, false, pne.NewProvider(ctx, c))
r.add(config.DiagnosticScrapeConfig, false, promcfg.NewProvider(ctx, c))
r.add(config.DiagnosticPrometheusVersion, false, promver.NewProvider(ctx, c))

Expand Down
64 changes: 32 additions & 32 deletions pkg/diagnostic/catalog/catalog_test.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
package catalog_test

import (
"context"
"testing"
"context"
"testing"

"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/catalog"
"github.com/stretchr/testify/assert"
"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/catalog"
"github.com/stretchr/testify/assert"
)

func TestRegistry_Get(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test getting providers with existing IDs
providers := r.Get(config.DiagnosticAPIKey, config.DiagnosticK8sVersion)
assert.Len(t, providers, 2)
// Test getting providers with existing IDs
providers := r.Get(config.DiagnosticAPIKey, config.DiagnosticK8sVersion)
assert.Len(t, providers, 2)

// Test getting providers with non-existing IDs
providers = r.Get("non-existing-id")
assert.Empty(t, providers)
// Test getting providers with non-existing IDs
providers = r.Get("non-existing-id")
assert.Empty(t, providers)

// Test getting providers with empty IDs
providers = r.Get()
assert.Empty(t, providers)
// Test getting providers with empty IDs
providers = r.Get()
assert.Empty(t, providers)
}

func TestRegistry_Has(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test checking for existing ID
has := r.Has(config.DiagnosticAPIKey)
assert.True(t, has)
// Test checking for existing ID
has := r.Has(config.DiagnosticAPIKey)
assert.True(t, has)

// Test checking for non-existing ID
has = r.Has("non-existing-id")
assert.False(t, has)
// Test checking for non-existing ID
has = r.Has("non-existing-id")
assert.False(t, has)
}

func TestRegistry_List(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test listing providers
providers := r.List()
assert.Len(t, providers, 7)
// Test listing providers
providers := r.List()
assert.Len(t, providers, 6) // Update the expected length to 6
}
Loading

0 comments on commit 934dcee

Please sign in to comment.