Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Jun 17, 2024
1 parent a356be4 commit bcdc697
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 233 deletions.
56 changes: 31 additions & 25 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
kclientcmd "k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"os"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -67,23 +66,6 @@ func main() {
klog.Fatal(errors.Wrap(err, "can't create configuration"))
}

promClient, err := promapi.NewClient(promapi.Config{Address: cfg.Prometheus.Host + ":" + strconv.Itoa(cfg.Prometheus.Port)})
if err != nil {
klog.Fatal(errors.Wrap(err, "error creating promClient"))
}

promApiClient := promv1.NewAPI(promClient)

logs, err := logging.NewLoggingFromConfig("Icinga Kubernetes", cfg.Logging)
if err != nil {
klog.Fatal(errors.Wrap(err, "can't configure logging"))
}

db2, err := igldatabase.NewDbFromConfig(&cfg.Database, logs.GetChildLogger("database"), igldatabase.RetryConnectorCallbacks{})
if err != nil {
klog.Fatal("IGL_DATABASE: ", err)
}

d, err := database.FromYAMLFile(configLocation)
if err != nil {
klog.Fatal(err)
Expand Down Expand Up @@ -115,6 +97,37 @@ func main() {
}

g, ctx := errgroup.WithContext(context.Background())

if cfg.Prometheus.Url != "" {
logs, err := logging.NewLoggingFromConfig("Icinga Kubernetes", cfg.Logging)
if err != nil {
klog.Fatal(errors.Wrap(err, "can't configure logging"))
}

db2, err := igldatabase.NewDbFromConfig(&cfg.Database, logs.GetChildLogger("database"), igldatabase.RetryConnectorCallbacks{})
if err != nil {
klog.Fatal("IGL_DATABASE: ", err)
}

promClient, err := promapi.NewClient(promapi.Config{Address: cfg.Prometheus.Url})
if err != nil {
klog.Fatal(errors.Wrap(err, "error creating promClient"))
}

promApiClient := promv1.NewAPI(promClient)
promMetricSync := metrics.NewPromMetricSync(promApiClient, db2)

g.Go(func() error {
return promMetricSync.Nodes(ctx, factory.Core().V1().Nodes().Informer())
})

g.Go(func() error {
return promMetricSync.Pods(ctx, factory.Core().V1().Pods().Informer())

//return promMetricSync.Run(ctx)
})
}

g.Go(func() error {
s := syncv1.NewSync(db, factory.Core().V1().Namespaces().Informer(), log.WithName("namespaces"), schemav1.NewNamespace)

Expand Down Expand Up @@ -207,13 +220,6 @@ func main() {

return s.Run(ctx)
})
g.Go(func() error {
promMetricSync := metrics.NewPromMetricSync(promApiClient, db2)

return promMetricSync.Pods(ctx, factory.Core().V1().Pods().Informer())

//return promMetricSync.Run(ctx)
})

errs := make(chan error, 1)
defer close(errs)
Expand Down
8 changes: 2 additions & 6 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ database:

# Configuration for Prometheus metrics API.
prometheus:

# Prometheus host
# host: http://localhost

# Prometheus port
# port: 9090
# Prometheus server URL
# host: http://localhost:9090
23 changes: 4 additions & 19 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@ package internal
import (
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-go-library/logging"
"github.com/pkg/errors"
"github.com/icinga/icinga-kubernetes/pkg/metrics"
)

// PrometheusConfig defines Prometheus configuration.
type PrometheusConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
}

// Validate checks constraints in the supplied Prometheus configuration and returns an error if they are violated.
func (c *PrometheusConfig) Validate() error {
if c.Host == "" {
return errors.New("Prometheus host missing")
}

return nil
}

// Config defines Icinga Kubernetes config.
type Config struct {
Database database.Config `yaml:"database"`
Logging logging.Config `yaml:"logging"`
Prometheus PrometheusConfig `yaml:"prometheus"`
Database database.Config `yaml:"database"`
Logging logging.Config `yaml:"logging"`
Prometheus metrics.PrometheusConfig `yaml:"prometheus"`
}

// Validate checks constraints in the supplied configuration and returns an error if they are violated.
Expand Down
9 changes: 1 addition & 8 deletions pkg/metrics/config.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package metrics

import "github.com/pkg/errors"

// PrometheusConfig defines Prometheus configuration.
type PrometheusConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Url string `yaml:"url"`
}

// Validate checks constraints in the supplied Prometheus configuration and returns an error if they are violated.
func (c *PrometheusConfig) Validate() error {
if c.Host == "" {
return errors.New("Prometheus host missing")
}

return nil
}
Loading

0 comments on commit bcdc697

Please sign in to comment.