Skip to content

Commit

Permalink
feat(integrationBehaviour): the integration accept a new parameter to… (
Browse files Browse the repository at this point in the history
#63)

* feat(integrationBehaviour): the integration accept a new parameter to change bahaviour
  • Loading branch information
paologallinaharbur authored Aug 24, 2020
1 parent 5512dcb commit 1b3f3fb
Show file tree
Hide file tree
Showing 45 changed files with 4,388 additions and 260 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ RUN chmod +x bin/nri-prometheus
FROM alpine:latest
RUN apk add --no-cache ca-certificates

# When standalone is set to true nri-prometheus does not require an infrastructure agent to work and send data
ENV STANDALONE=TRUE

USER nobody
COPY --from=build /go/src/github.com/newrelic/nri-prometheus/bin/nri-prometheus /bin/
ENTRYPOINT ["/bin/nri-prometheus"]
3 changes: 3 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ RUN apk add --no-cache ca-certificates
USER nobody
ADD bin/nri-prometheus /bin/

# When standalone is set to true nri-prometheus does not require an infrastructure agent to work and send data
ENV STANDALONE=TRUE

ENTRYPOINT ["/bin/nri-prometheus"]
3 changes: 3 additions & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ USER nobody

ENTRYPOINT ["/bin/nri-prometheus"]

# When standalone is set to true nri-prometheus does not require an infrastructure agent to work and send data
ENV STANDALONE=TRUE

COPY nri-prometheus /bin/nri-prometheus
30 changes: 26 additions & 4 deletions cmd/nri-prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,46 @@ package main

import (
"fmt"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"

"github.com/newrelic/infra-integrations-sdk/args"
"github.com/newrelic/nri-prometheus/internal/cmd/scraper"
"github.com/pkg/errors"
"github.com/spf13/viper"
)

// ArgumentList Available Arguments
type ArgumentList struct {
ConfigPath string `default:"" help:"Path to the config file"`
}

func loadConfig() (*scraper.Config, error) {

c := ArgumentList{}
err := args.SetupArgs(&c)
if err != nil {
return nil, err
}

cfg := viper.New()
cfg.SetConfigName("config")
cfg.SetConfigType("yaml")
cfg.AddConfigPath("/etc/nri-prometheus/")
cfg.AddConfigPath(".")

if c.ConfigPath != "" {
cfg.AddConfigPath(filepath.Dir(c.ConfigPath))
cfg.SetConfigName(filepath.Base(c.ConfigPath))
} else {
cfg.SetConfigName("config")
cfg.AddConfigPath("/etc/nri-prometheus/")
cfg.AddConfigPath(".")
}

setViperDefaults(cfg)

err := cfg.ReadInConfig()
err = cfg.ReadInConfig()
if err != nil {
return nil, errors.Wrap(err, "could not read configuration")
}
Expand Down Expand Up @@ -54,6 +75,7 @@ func setViperDefaults(viper *viper.Viper) {
viper.SetDefault("emitter_harvest_period", "1s")
viper.SetDefault("auto_decorate", false)
viper.SetDefault("insecure_skip_verify", false)
viper.SetDefault("standalone", false)
viper.SetDefault("percentiles", []float64{50.0, 95.0, 99.0})
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/nri-prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ func main() {
logrus.WithError(err).Fatal("while loading configuration")
}

err = scraper.Run(cfg)
if err != nil {
logrus.WithError(err).Fatal("error occurred while running scraper")
if cfg.Standalone {
err = scraper.Run(cfg)
if err != nil {
logrus.WithError(err).Fatal("error occurred while running scraper")
}
} else {
logrus.Info("New behaviour!")
}
}
27 changes: 27 additions & 0 deletions configs/nri-prometheus-config.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
integrations:
- name: nri-prometheus
inventory_source: integration/com.newrelic.prometheus
config:
# The name of your cluster. It's important to match other New Relic products to relate the data.
cluster_name: "my_exporter"

#targets:
# - description: Secure etcd example
# urls: ["https://192.168.3.1:2379", "https://192.168.3.2:2379", "https://192.168.3.3:2379"]
# tls_config:
# ca_file_path: "/etc/etcd/etcd-client-ca.crt"
# cert_file_path: "/etc/etcd/etcd-client.crt"
# key_file_path: "/etc/etcd/etcd-client.key"

# Wether the integration should run in verbose mode or not. Defaults to false.
verbose: false

# The HTTP client timeout when fetching data from endpoints. Defaults to 30s.
# scrape_timeout: "30s"

# Wether the integration should skip TLS verification or not. Defaults to false.
insecure_skip_verify: false

timeout: 10s


2 changes: 2 additions & 0 deletions deploy/local.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ data:
config.yaml: |
# The name of your cluster. It's important to match other New Relic products to relate the data.
cluster_name: "<YOUR_CLUSTER_NAME>"
# When standalone is set to true nri-prometheus does not require an infrastructure agent to work and send data
standalone: true
# How often the integration should run. Defaults to 30s.
# scrape_duration: "30s"
# The HTTP client timeout when fetching data from endpoints. Defaults to 30s.
Expand Down
3 changes: 3 additions & 0 deletions deploy/nri-prometheus.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ data:
# The name of your cluster. It's important to match other New Relic products to relate the data.
cluster_name: "<YOUR_CLUSTER_NAME>"
# When standalone is set to true nri-prometheus does not require an infrastructure agent to work and send data
standalone: true
# How often the integration should run. Defaults to 30s.
# scrape_duration: "30s"
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ require (
github.com/googleapis/gnostic v0.2.3-0.20181019180348-e2aafd60c944 // indirect
github.com/hashicorp/hcl v1.0.1-0.20190611123218-cf7d376da96d // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/newrelic/infra-integrations-sdk v3.6.4+incompatible
github.com/newrelic/newrelic-telemetry-sdk-go v0.4.0
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/pelletier/go-toml v1.2.1-0.20181124002727-27c6b39a135b // indirect
github.com/pkg/errors v0.8.1-0.20180311214515-816c9085562c
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.3
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
github.com/prometheus/common v0.4.0
github.com/sirupsen/logrus v1.3.0
github.com/spf13/cast v1.3.1-0.20190531093228-c01685bb8421 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.4.1-0.20190729163700-33bf76add3b7
github.com/spf13/viper v1.7.1
github.com/stretchr/objx v0.1.2-0.20180626195558-9e1dfc121bca // indirect
github.com/stretchr/testify v1.6.1
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
k8s.io/api v0.16.10
k8s.io/apimachinery v0.16.10
k8s.io/client-go v0.15.12
Expand Down
Loading

0 comments on commit 1b3f3fb

Please sign in to comment.