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

Commit

Permalink
fix(logs): fixed labels that are used for log collecting and added at…
Browse files Browse the repository at this point in the history
…tribute (#68)

* fix(charts): added checking if newer version of the chart are available

* fix(logs): fixed labels that are used for log collecting

* fix(log): added attribute to log
  • Loading branch information
stebenz authored Mar 4, 2020
1 parent 59185c1 commit d4ff1f3
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetChartInfo() *chart.Chart {

func GetImageTags() map[string]string {
return map[string]string{
"quay.io/datawire/aes": "1.2.0",
"quay.io/datawire/aes": "1.2.1",
"prom/statsd-exporter": "v0.8.1",
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/ambassador/info"
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"app.kubernetes.io/instance": "ambassador",
"app.kubernetes.io/name": "ambassador",
}

return &logging.FlowConfig{
Name: "flow-ambassador",
Expand Down
7 changes: 4 additions & 3 deletions internal/bundle/application/applications/argocd/logs/logs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/argocd/info"
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"app.kubernetes.io/instance": "argocd",
"app.kubernetes.io/part-of": "argocd",
}

return &logging.FlowConfig{
Name: "flow-argocd",
Expand Down
7 changes: 4 additions & 3 deletions internal/bundle/application/applications/grafana/logs/logs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/grafana/info"
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"app.kubernetes.io/instance": "grafana",
"app.kubernetes.io/name": "grafana",
}

return &logging.FlowConfig{
Name: "flow-grafana",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/kubestatemetrics/info"
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"app.kubernetes.io/instance": "kube-state-metrics",
"app.kubernetes.io/name": "kube-state-metrics",
}

return &logging.FlowConfig{
Name: "flow-kube-state-metrics",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/bundle/application/applications/prometheus/info"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"app": "prometheus",
"prometheus": "caos-prometheus",
}

return &logging.FlowConfig{
Name: "flow-prometheus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/bundle/application/applications/prometheusnodeexporter/info"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"release": "prometheus-node-exporter",
"app": "prometheus-node-exporter",
}

return &logging.FlowConfig{
Name: "flow-prometheus-node-exporter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package logs

import (
"github.com/caos/boom/internal/bundle/application/applications/loggingoperator/logging"
"github.com/caos/boom/internal/bundle/application/applications/prometheusoperator/info"
"github.com/caos/boom/internal/labels"
)

func GetFlow(outputs []string) *logging.FlowConfig {
ls := labels.GetApplicationLabels(info.GetName())
ls := map[string]string{
"release": "prometheus-operator",
"app": "prometheus-operator-operator",
}

return &logging.FlowConfig{
Name: "flow-prometheus-operator",
Expand Down
6 changes: 5 additions & 1 deletion internal/templator/helm/chart/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ func All(monitor mntr.Monitor, basePath string) error {
return err
}

monitor.Info("Checking newer chart versions")
if err := CompareVersions(monitor, basePath, charts); err != nil {
return err
}

monitor.Info("Fetching all charts")
for _, chart := range charts {
if err := fetch(monitor, basePath, chart); err != nil {
return err
}

}
return nil
}
Expand Down
88 changes: 88 additions & 0 deletions internal/templator/helm/chart/fetch/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package fetch

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/caos/boom/internal/helper"
"github.com/caos/orbiter/mntr"
"gopkg.in/yaml.v3"
)

type index struct {
APIVersion string `yaml:"apiVersion"`
Entries map[string][]entry `yaml:"entries"`
}

type entry struct {
Version string `yaml:"version"`
AppVersion string `yaml:"appVersion"`
}

func CompareVersions(monitor mntr.Monitor, basePath string, charts []*ChartInfo) error {

indexFolderPathAbs, err := helper.GetAbsPath(basePath, "helm", "repository", "cache")
if err != nil {
return err
}

indexFiles := make(map[string]*index, 0)
err = filepath.Walk(indexFolderPathAbs, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}

data, err := ioutil.ReadFile(path)
if err != nil {
return err
}

var indexFile index
if err := yaml.Unmarshal(data, &indexFile); err != nil {
return err
}

indexFiles[strings.TrimSuffix(info.Name(), "-index.yaml")] = &indexFile
// for k, v := range indexFile.Entries {
// indexFiles[strings.TrimSuffix(info.Name(), "-index.yaml")].Entries[k] = v
// }
return nil
})
if err != nil {
return err
}
for _, chart := range charts {
indexFile := indexFiles[chart.IndexName]
for _, entry := range indexFile.Entries[chart.Name] {
entryParts := strings.Split(entry.Version, ".")
entryPartsInt := make([]int, 3)
for k, v := range entryParts {
entryPartsInt[k], _ = strconv.Atoi(v)
}

chartParts := strings.Split(chart.Version, ".")
chartPartsInt := make([]int, 3)
for k, v := range chartParts {
chartPartsInt[k], _ = strconv.Atoi(v)
}
if entryPartsInt[0] > chartPartsInt[0] ||
(entryPartsInt[0] == chartPartsInt[0] && entryPartsInt[1] > chartPartsInt[1]) ||
(entryPartsInt[0] == chartPartsInt[0] && entryPartsInt[1] == chartPartsInt[1] && entryPartsInt[2] > chartPartsInt[2]) {

logFields := map[string]interface{}{
"oldVersion": chart.Version,
"newVersion": entry.Version,
"index": chart.IndexName,
"chart": chart.Name,
"newAppVersion": entry.AppVersion,
}
monitor.WithFields(logFields).Info("Tshere is a newer version")
}
}
}

return nil
}

0 comments on commit d4ff1f3

Please sign in to comment.