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

Add SLI source defaults #9

Merged
merged 9 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
services:
- docker
go:
- "1.11"
- "1.13"

before_install:
# Upgrade default docker
Expand Down
31 changes: 20 additions & 11 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
## 0.2.0 / 2018-11-14

This release breaks the CRD apiVersion and the current registered CRDs needs to be re registered with `apiVersion: monitoring.spotahome.com/v1alpha1`.
## [Unreleased]
### Added
- Default SLI input configurations for the SLOs that don't have SLI inputs.

* [CHANGE] Move CRD api from `apiVersion: measure.slok.xyz/v1alpha1` to `apiVersion: monitoring.spotahome.com/v1alpha1`.
* [CHANGE] Move repository from github.com/slok/service-level-operator to github.com/spotahome/service-level-operator.
* [FEATURE] Add Grafana dashboard.
## [0.2.0] - 2018-11-14
### Added
- Grafana dashboard.

## 0.1.0 / 2018-10-31
### Changed
- Move CRD api from `apiVersion: measure.slok.xyz/v1alpha1` to `apiVersion: monitoring.spotahome.com/v1alpha1`.
- Move repository from github.com/slok/service-level-operator to github.com/spotahome/service-level-operator.

* [FEATURE] Add prometheus metrics for the SLI processing flow.
* [FEATURE] Add deploy example manifests for Kubernetes.
* [FEATURE] Add Prometheus SLI inputs and SLI result outputs.
* [FEATURE] Add operator.
* [FEATURE] Add service level CRD.
## [0.1.0] - 2018-10-31
### Added
- Prometheus metrics for the SLI processing flow.
- Deploy example manifests for Kubernetes.
- Prometheus SLI inputs and SLI result outputs.
- Operator.
- Service level CRD.

[Unreleased]: https://github.com/spotahome/service-level-operator/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/spotahome/service-level-operator/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/spotahome/service-level-operator/releases/tag/v0.1.0
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FAKE_CMD := $(DEV_CMD) --fake
K8S_CODE_GEN_CMD := ./hack/scripts/k8scodegen.sh
OPENAPI_CODE_GEN_CMD := ./hack/scripts/openapicodegen.sh
DEPS_CMD := GO111MODULE=on go mod tidy && GO111MODULE=on go mod vendor
K8S_VERSION := 1.11.3
K8S_VERSION := 1.13.12
SET_K8S_DEPS_CMD := GO111MODULE=on go mod edit \
-require=k8s.io/apiextensions-apiserver@kubernetes-${K8S_VERSION} \
-require=k8s.io/client-go@kubernetes-${K8S_VERSION} \
Expand Down
39 changes: 38 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,49 @@ There is a [grafana dashboard][grafana-dashboard] to show the SLO's status.

## Supported input/output backends

### Input
### Input (SLI sources)

Inputs for SLIs can be declared at two levels.

At SLO level (this way we can use different endpoint for each SLO)

```yaml
...
serviceLevelObjectives:
- name: "my_slok"
...
serviceLevelIndicator:
prometheus:
address: http://myprometheus:9090
...
```

Also, if any of the SLOs does not have a default input, setting a default SLI source configuration when running the operator will fallback to these.

The flag is `--def-sli-source-path` and the file format is this:

```json
{
"prometheus": {
"address": "http://127.0.0.1:9090"
}
}
```

Example:

```bash
--def-sli-source-path <(echo '{"prometheus": {"address": "http://127.0.0.1:12345"}}')
```

List of supported SLI sources:

- [Prometheus]

### Output

Outputs are how the SLO metrics will be exported. Here is a list of supported output backends:

- [Prometheus]

## Query examples
Expand Down
2 changes: 1 addition & 1 deletion alerts/slo_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rule_files:
- alerts/slo.yaml
- slo.yaml

evaluation_interval: 1m

Expand Down
2 changes: 2 additions & 0 deletions cmd/service-level-operator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type cmdFlags struct {
listenAddress string
labelSelector string
namespace string
defSLISourcePath string
debug bool
development bool
fake bool
Expand All @@ -52,6 +53,7 @@ func (c *cmdFlags) init() {
c.fs.StringVar(&c.listenAddress, "listen-addr", defListenAddress, "the address where the metrics will be exposed")
c.fs.StringVar(&c.labelSelector, "selector", "", "selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
c.fs.StringVar(&c.namespace, "namespace", "", "the namespace to filter on, by default all")
c.fs.StringVar(&c.defSLISourcePath, "def-sli-source-path", "", "the path to the default sli sources configuration file")
c.fs.IntVar(&c.resyncSeconds, "resync-seconds", defResyncSeconds, "the number of seconds for the SLO calculation interval")
c.fs.IntVar(&c.workers, "workers", defWorkers, "the number of concurrent workers per controller handling events")
c.fs.BoolVar(&c.development, "development", false, "development flag will allow to run the operator outside a kubernetes cluster")
Expand Down
40 changes: 35 additions & 5 deletions cmd/service-level-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
apiextensionscli "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

Expand All @@ -22,6 +23,7 @@ import (
"github.com/spotahome/service-level-operator/pkg/operator"
kubernetesclifactory "github.com/spotahome/service-level-operator/pkg/service/client/kubernetes"
promclifactory "github.com/spotahome/service-level-operator/pkg/service/client/prometheus"
"github.com/spotahome/service-level-operator/pkg/service/configuration"
kubernetesservice "github.com/spotahome/service-level-operator/pkg/service/kubernetes"
"github.com/spotahome/service-level-operator/pkg/service/metrics"
)
Expand Down Expand Up @@ -113,7 +115,27 @@ func (m *Main) Run() error {

// Operator.
{
promCliFactory := m.createPrometheusCliFactory()

// Load configuration.
var cfgSLISrc *configuration.DefaultSLISource
if m.flags.defSLISourcePath != "" {
f, err := os.Open(m.flags.defSLISourcePath)
if err != nil {
return err
}
defer f.Close()
cfgSLISrc, err = configuration.JSONLoader{}.LoadDefaultSLISource(context.Background(), f)
if err != nil {
return err
}
}

// Create SLI source client factories.
promCliFactory, err := m.createPrometheusCliFactory(cfgSLISrc)
if err != nil {
return err
}

cfg := m.flags.toOperatorConfig()
op, err := operator.New(cfg, promReg, promCliFactory, k8ssvc, metricssvc, m.logger)
if err != nil {
Expand Down Expand Up @@ -161,7 +183,6 @@ func (m *Main) loadKubernetesConfig() (*rest.Config, error) {
}

func (m *Main) createKubernetesClients() (kubernetes.Interface, crdcli.Interface, apiextensionscli.Interface, error) {

var factory kubernetesclifactory.ClientFactory

if m.flags.fake {
Expand Down Expand Up @@ -192,12 +213,21 @@ func (m *Main) createKubernetesClients() (kubernetes.Interface, crdcli.Interface
return stdcli, crdcli, aexcli, nil
}

func (m *Main) createPrometheusCliFactory() promclifactory.ClientFactory {
func (m *Main) createPrometheusCliFactory(cfg *configuration.DefaultSLISource) (promclifactory.ClientFactory, error) {
if m.flags.fake {
return promclifactory.NewFakeFactory()
return promclifactory.NewFakeFactory(), nil
}

f := promclifactory.NewBaseFactory()
if cfg != nil && cfg.Prometheus.Address != "" {
err := f.WithDefaultV1APIClient(cfg.Prometheus.Address)
if err != nil {
return nil, err
}
m.logger.Infof("prometheus default SLI source set to: %s", cfg.Prometheus.Address)
}

return promclifactory.NewFactory()
return f, nil
}

// createHTTPServer creates the http server that serves prometheus metrics and healthchecks.
Expand Down
2 changes: 1 addition & 1 deletion docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine
FROM golang:1.13-alpine

RUN apk --no-cache add \
bash \
Expand Down
8 changes: 4 additions & 4 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.11-alpine AS build-stage
FROM golang:1.13-alpine AS build-stage

RUN apk --no-cache add \
g++ \
git \
make
g++ \
git \
make

ARG VERSION
ENV VERSION=${VERSION}
Expand Down
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module github.com/spotahome/service-level-operator

require (
github.com/emicklei/go-restful v2.8.0+incompatible // indirect
github.com/go-openapi/spec v0.17.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/oklog/run v1.0.0
github.com/prometheus/client_golang v0.9.0-pre1.0.20181001174001-0a8115f42e03
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e
github.com/sirupsen/logrus v1.2.0
github.com/spotahome/kooper v0.5.0
github.com/stretchr/testify v1.2.2
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
k8s.io/apiextensions-apiserver v0.0.0-20180910084140-b05d9bb7cc74
k8s.io/apimachinery v0.0.0-20180904193909-def12e63c512
k8s.io/client-go v2.0.0-alpha.0.0.20180910083459-2cefa64ff137+incompatible
k8s.io/kube-openapi v0.0.0-20180928202339-9dfdf9be683f
github.com/prometheus/client_golang v1.2.1
github.com/prometheus/common v0.7.0
github.com/sirupsen/logrus v1.4.2
github.com/spotahome/kooper v0.6.1-0.20190926114429-1c6a0cfab9a5
github.com/stretchr/testify v1.4.0
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6
k8s.io/api v0.0.0-20191004102255-dacd7df5a50b // indirect
k8s.io/apiextensions-apiserver v0.0.0-20191004105443-a7d558db75c6
k8s.io/apimachinery v0.0.0-20191004074956-01f8b7d1121a
k8s.io/client-go v0.0.0-20191004102537-eb5b9a8cfde7
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d
)

go 1.13
Loading