Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce experimental cluster-aware metrics subsystem #1261

Closed
wants to merge 15 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/.vscode
vendor

agent-data
/cmd/agent/agent
/cmd/agentctl/agentctl
/cmd/agent-operator/agent-operator
Expand Down
26 changes: 26 additions & 0 deletions cmd/agent/agent-cluster-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server:
log_level: debug

metrics:
global:
scrape_interval: 1m
configs:
- name: default
scrape_configs:
- job_name: demo.robustperception.io
static_configs:
- targets: ['demo.robustperception.io:3000']
labels:
app: grafana
- targets: ['demo.robustperception.io:9090']
labels:
app: prometheus
- targets: ['demo.robustperception.io:9100']
labels:
app: node_exporter
- targets: ['demo.robustperception.io:9093']
labels:
app: alertmanager
- targets: ['demo.robustperception.io:9091']
labels:
app: pushgateway
Comment on lines +10 to +26
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used for quick testing but we probably shouldn't hammer the robustperception demo server by making it an official example config :)

31 changes: 27 additions & 4 deletions cmd/agent/entrypoint.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"net"
"net/http"
Expand All @@ -11,8 +12,9 @@ import (
"syscall"

"github.com/gorilla/mux"

"github.com/grafana/agent/pkg/cluster"
"github.com/grafana/agent/pkg/logs"
"github.com/grafana/agent/pkg/metrics"
"github.com/grafana/agent/pkg/metrics/instance"
"github.com/grafana/agent/pkg/traces"
"github.com/grafana/agent/pkg/util"
Expand All @@ -38,7 +40,8 @@ type Entrypoint struct {
cfg config.Config

srv *server.Server
promMetrics *metrics.Agent
cluster *cluster.Node
promMetrics config.Metrics
lokiLogs *logs.Logs
tempoTraces *traces.Traces
integrations config.Integrations
Expand Down Expand Up @@ -74,8 +77,9 @@ func NewEntrypoint(logger *util.Logger, cfg *config.Config, reloader Reloader) (
}

ep.srv = server.New(prometheus.DefaultRegisterer, logger)
ep.cluster = cluster.NewNode(logger, &cfg.Cluster)

ep.promMetrics, err = metrics.New(prometheus.DefaultRegisterer, cfg.Metrics, logger)
ep.promMetrics, err = config.NewMetrics(logger, prometheus.DefaultRegisterer, &cfg.Metrics, ep.cluster)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -150,7 +154,7 @@ func (ep *Entrypoint) ApplyConfig(cfg config.Config) error {
}

// Go through each component and update it.
if err := ep.promMetrics.ApplyConfig(cfg.Metrics); err != nil {
if err := ep.promMetrics.ApplyConfig(&cfg.Metrics); err != nil {
level.Error(ep.log).Log("msg", "failed to update prometheus", "err", err)
failed = true
}
Expand Down Expand Up @@ -185,6 +189,8 @@ func (ep *Entrypoint) ApplyConfig(cfg config.Config) error {
// wire is used to hook up API endpoints to components, and is called every
// time a new Weaveworks server is creatd.
func (ep *Entrypoint) wire(mux *mux.Router, grpc *grpc.Server) {
ep.cluster.Wire(mux, grpc)

ep.promMetrics.WireAPI(mux)
ep.promMetrics.WireGRPC(grpc)

Expand Down Expand Up @@ -261,6 +267,7 @@ func (ep *Entrypoint) Stop() {
ep.lokiLogs.Stop()
ep.promMetrics.Stop()
ep.tempoTraces.Stop()
ep.cluster.Close()
ep.srv.Close()

if ep.reloadServer != nil {
Expand Down Expand Up @@ -306,6 +313,22 @@ func (ep *Entrypoint) Start() error {
ep.srv.Close()
})

// Cluster
{
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

g.Add(func() error {
if err := ep.cluster.Start(); err != nil {
return err
}
<-ctx.Done()
return nil
}, func(error) {
cancel()
})
}

go func() {
for range notifier {
ep.TriggerReload()
Expand Down
99 changes: 99 additions & 0 deletions example/k3d/environment/metrics-next/main.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
local default = import 'default/main.libsonnet';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe any kind of k3d code should be moved to another PR and defer to docker-compose for the initial PR?

local gragent = import 'grafana-agent/v2/main.libsonnet';
local k = import 'ksonnet-util/kausal.libsonnet';

local ingress = k.networking.v1beta1.ingress;
local pvc = k.core.v1.persistentVolumeClaim;
local path = k.networking.v1beta1.httpIngressPath;
local rule = k.networking.v1beta1.ingressRule;
local container = k.core.v1.container;
local volumeMount = k.core.v1.volumeMount;

local images = {
agent: 'grafana/agent:latest',
agentctl: 'grafana/agentctl:latest',
};

{
default: default.new(namespace='default') {
grafana+: {
ingress+:
ingress.new('grafana-ingress') +
ingress.mixin.spec.withRules([
rule.withHost('grafana.k3d.localhost') +
rule.http.withPaths([
path.withPath('/')
+ path.backend.withServiceName('grafana')
+ path.backend.withServicePort(80),
]),
]),
},
},

logging_agents:
gragent.new(name='grafana-agent-logs', namespace='default') +
gragent.withImagesMixin(images) +
gragent.withDaemonSetController() +
gragent.withLogVolumeMounts() +
gragent.withLogPermissions() +
gragent.withAgentConfig({
server: { log_level: 'debug' },

logs: {
positions_directory: '/tmp/loki-positions',
configs: [{
name: 'default',
clients: [{
url: 'http://loki.default.svc.cluster.local/loki/api/v1/push',
external_labels: { cluster: 'k3d' },
}],
scrape_configs: [
x { pipeline_stages: [{ cri: {} }] }
for x
in gragent.newKubernetesLogs()
],
}],
},
}),


agent_cluster:
gragent.new(name='grafana-agent', namespace='default') {
container+:: container.withArgsMixin(k.util.mapToFlags({
'cluster.enable': 'true',
'cluster.discover-peers': 'provider=k8s namespace=default label_selector="name=grafana-agent"',

'enable-features': 'metrics-next',
'metrics.wal.directory': '/var/lib/agent',
})),
} +
gragent.withImagesMixin(images) +
gragent.withStatefulSetController(
replicas=3,
volumeClaims=[
pvc.new() +
pvc.mixin.metadata.withName('agent-wal') +
pvc.mixin.metadata.withNamespace('smoke') +
pvc.mixin.spec.withAccessModes('ReadWriteOnce') +
pvc.mixin.spec.resources.withRequests({ storage: '5Gi' }),
],
) +
gragent.withVolumeMountsMixin([volumeMount.new('agent-wal', '/var/lib/agent')]) +
gragent.withAgentConfig({
server: { log_level: 'debug' },

metrics: {
global: {
scrape_interval: '15s',
external_labels: { cluster: 'k3d' },
},
configs: [{
name: 'default',
scrape_configs: gragent.newKubernetesMetrics({}),
remote_write: [{
url: 'http://cortex.default.svc.cluster.local/api/prom/push',
}],
}],
},
}),
}
11 changes: 11 additions & 0 deletions example/k3d/environment/metrics-next/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"apiVersion": "tanka.dev/v1alpha1",
"kind": "Environment",
"metadata": {
"name": "default"
},
"spec": {
"apiServer": "https://0.0.0.0:50443",
"namespace": "default"
}
}
9 changes: 9 additions & 0 deletions example/k3d/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
}
},
"version": ""
},
{
"source": {
"git": {
"remote": "https://github.com/grafana/grafonnet-lib.git",
"subdir": "grafonnet"
}
},
"version": "master"
}
],
"legacyImports": true
Expand Down
19 changes: 17 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ require (
github.com/grafana/loki v1.6.2-0.20211021114919-0ae0d4da122d
github.com/hashicorp/consul/api v1.11.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-discover v0.0.0-20211203145537-8b3ddf4349a8
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/infinityworks/github-exporter v0.0.0-20201016091012-831b72461034
github.com/jsternberg/zap-logfmt v1.2.0
github.com/lib/pq v1.10.1
Expand Down Expand Up @@ -64,6 +66,7 @@ require (
github.com/prometheus/prometheus v1.8.2-0.20211102100715-d4c83da6d252
github.com/prometheus/statsd_exporter v0.22.2
github.com/rancher/k3d/v5 v5.2.2
github.com/rfratto/ckit v0.0.0-20220114184126-aeebd522ec88
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
Expand All @@ -79,6 +82,7 @@ require (
go.uber.org/zap v1.19.1
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
Expand All @@ -100,6 +104,8 @@ require (
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.21 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
Expand All @@ -125,6 +131,7 @@ require (
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/checkpoint-restore/go-criu/v5 v5.0.0 // indirect
github.com/cilium/ebpf v0.7.0 // indirect
Expand All @@ -141,6 +148,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba // indirect
github.com/digitalocean/godo v1.69.1 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/docker/cli v20.10.10+incompatible // indirect
Expand Down Expand Up @@ -196,14 +204,15 @@ require (
github.com/hashicorp/go-hclog v0.16.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/mdns v1.0.1 // indirect
github.com/hashicorp/memberlist v0.2.4 // indirect
github.com/hashicorp/serf v0.9.5 // indirect
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 // indirect
github.com/hetznercloud/hcloud-go v1.32.0 // indirect
github.com/hodgesds/perf-utils v0.4.0 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
Expand All @@ -222,6 +231,7 @@ require (
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 // indirect
github.com/joyent/triton-go v0.0.0-20180628001255-830d2b111e62 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jsimonetti/rtnetlink v0.0.0-20211022192332-93da33804786 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down Expand Up @@ -261,6 +271,7 @@ require (
github.com/mrunalp/fileutils v0.5.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/ncabatoff/go-seq v0.0.0-20180805175032-b08ef85ed833 // indirect
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter v0.40.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.40.0 // indirect
Expand All @@ -276,6 +287,7 @@ require (
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.8.2 // indirect
github.com/openzipkin/zipkin-go v0.3.0 // indirect
github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/percona/exporter_shared v0.7.3 // indirect
github.com/percona/percona-toolkit v0.0.0-20210803120725-d14d18a1bfb6 // indirect
Expand All @@ -285,6 +297,7 @@ require (
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/exporter-toolkit v0.7.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/renier/xmlrpc v0.0.0-20170708154548-ce4a1a486c03 // indirect
github.com/rs/cors v1.8.0 // indirect
github.com/safchain/ethtool v0.1.0 // indirect
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da // indirect
Expand All @@ -297,6 +310,7 @@ require (
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a // indirect
github.com/spf13/afero v1.6.0 // indirect
Expand All @@ -307,13 +321,15 @@ require (
github.com/stretchr/objx v0.2.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tencentcloud/tencentcloud-sdk-go v1.0.162 // indirect
github.com/theupdateframework/notary v0.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 // indirect
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect
github.com/vmware/govmomi v0.19.0 // indirect
github.com/weaveworks/promrus v1.2.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
Expand Down Expand Up @@ -347,7 +363,6 @@ require (
google.golang.org/api v0.59.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211112145013-271947fe86fd // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading