Skip to content
This repository was archived by the owner on Jul 28, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dde0adf
convert smoke script to go program
rlankfo Jan 4, 2022
e2ed6f0
update build for agent-smoke
rlankfo Jan 4, 2022
9ed01b2
fix pr comments
rlankfo Jan 4, 2022
88349f3
use existing log helper package
rlankfo Jan 5, 2022
d07629b
refactor context cancel
rlankfo Jan 5, 2022
163f56f
update exit codes
rlankfo Jan 5, 2022
2d6d7bd
use ticker
rlankfo Jan 5, 2022
782452c
prefer oklog/run instead of errgroup
rlankfo Jan 5, 2022
91490dc
use nop logger
rlankfo Jan 5, 2022
821d780
refactor task interface
rlankfo Jan 5, 2022
c65d48b
remove functional options
rlankfo Jan 5, 2022
3d15d40
log.With for task loggers
rlankfo Jan 5, 2022
3a5ad0f
move smoke to tools
rlankfo Jan 5, 2022
86e03b5
build smoke image, push to internal registry
rlankfo Jan 5, 2022
eff9747
move crow to tools
rlankfo Jan 5, 2022
d065a65
add gcr_admin secret
rlankfo Jan 6, 2022
62e167b
fix link to crow
rlankfo Jan 6, 2022
9a087c3
add smoke libsonnet and use in local k3d smoke test
rlankfo Jan 6, 2022
53991b0
add deletePodBySelectorTask
rlankfo Jan 7, 2022
45c76f8
scale smoke-test replica down after local test
rlankfo Jan 7, 2022
97f9e11
refactor smoke Options to Config
rlankfo Jan 7, 2022
e39c2e6
update duration usage message
rlankfo Jan 7, 2022
0c21add
add some basic unit tests
rlankfo Jan 7, 2022
e391b77
newlines
rlankfo Jan 7, 2022
5f9f7fa
pass mutation frequency and chaos frequency from smoke script
rlankfo Jan 10, 2022
f3c9d78
pull crow image from gcr
rlankfo Jan 10, 2022
903ce4f
update smoke script
rlankfo Jan 10, 2022
261dd97
move monitoring to smoke libsonnet
rlankfo Jan 12, 2022
cce1f3e
move additional smoke resources needed in deployment tools
rlankfo Jan 12, 2022
ea25162
reference libsonnet files from grafana-agent dep
rlankfo Jan 13, 2022
afae39f
make drone
rlankfo Jan 20, 2022
64291d9
fix images in smoke script
rlankfo Jan 20, 2022
d6beae5
get rid of extVars
rlankfo Jan 20, 2022
068ef01
update k3d example environment to reference etcd from new location
rlankfo Jan 20, 2022
cab79f7
update smoke docker builds to use go1.17
rlankfo Jan 20, 2022
da0e9ce
use pointer.Int64
rlankfo Jan 20, 2022
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
17 changes: 15 additions & 2 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ steps:
- tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz
- rm go1.17.6.linux-amd64.tar.gz
- export PATH=$PATH:/usr/local/go/bin
- make cmd/agent/agent cmd/agentctl/agentctl cmd/agent-operator/agent-operator cmd/grafana-agent-crow/grafana-agent-crow
- make cmd/agent/agent cmd/agentctl/agentctl cmd/agent-operator/agent-operator tools/crow/grafana-agent-crow tools/smoke/grafana-agent-smoke
- make K8S_USE_DOCKER_NETWORK=1 DRONE=true BUILD_IN_CONTAINER=false test
depends_on:
- Lint
Expand Down Expand Up @@ -113,7 +113,11 @@ steps:
from_secret: DOCKER_LOGIN
DOCKER_PASSWORD:
from_secret: DOCKER_PASSWORD
GCR_CREDS:
from_secret: gcr_admin
commands:
- mkdir -p $HOME/.docker
- printenv GCR_CREDS > $HOME/.docker/config.json
- docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- apk update && apk add make bash wget git qemu
- wget -q https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64
Expand All @@ -128,6 +132,7 @@ steps:
- make DRONE=true CROSS_BUILD=true BUILD_IN_CONTAINER=true RELEASE_BUILD=true agentctl-image
- make DRONE=true CROSS_BUILD=true BUILD_IN_CONTAINER=true RELEASE_BUILD=true agent-operator-image
- make DRONE=true CROSS_BUILD=true BUILD_IN_CONTAINER=true RELEASE_BUILD=true grafana-agent-crow-image
- make DRONE=true CROSS_BUILD=true BUILD_IN_CONTAINER=true RELEASE_BUILD=true agent-smoke-image
- docker buildx rm multiarch

depends_on:
Expand Down Expand Up @@ -243,6 +248,14 @@ get:
path: secret/data/common/gcr
name: .dockerconfigjson

---
kind: secret
name: gcr_admin

get:
name: .dockerconfigjson
path: infra/data/ci/gcr-admin

---
kind: secret
name: gh_token
Expand All @@ -252,6 +265,6 @@ get:
name: pat
---
kind: signature
hmac: 87a9a23731884dac8e0b5c3ee0fa2b5cef9d7fa490fcad649f7783f6ea9d2d32
hmac: f59c8b25058782d021a2d6bdc1fc59a049f3b352fb41de6a14c28fd05f578073

...
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ IMAGE_BRANCH_TAG = latest
endif
DRONE ?= false

# INTERNAL_REGISTRY used for pushing images to grafana internal registry
INTERNAL_REGISTRY ?= us.gcr.io/kubernetes-dev

# TARGETPLATFORM is specifically called from `docker buildx --platform`, this is mainly used when pushing docker image manifests, normal generally means NON DRONE builds
TARGETPLATFORM ?=normal

Expand Down Expand Up @@ -180,7 +183,8 @@ all: protos agent agentctl
agent: cmd/agent/agent
agentctl: cmd/agentctl/agentctl
agent-operator: cmd/agent-operator/agent-operator
grafana-agent-crow: cmd/grafana-agent-crow/grafana-agent-crow
agent-smoke: tools/smoke/grafana-agent-smoke
grafana-agent-crow: tools/crow/grafana-agent-crow

# In general DRONE variable should overwrite any other options, if DRONE is not set then fallback to normal behavior

Expand All @@ -196,24 +200,33 @@ cmd/agent-operator/agent-operator: cmd/agent-operator/main.go
$(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

cmd/grafana-agent-crow/grafana-agent-crow: cmd/grafana-agent-crow/main.go
tools/crow/grafana-agent-crow: tools/crow/main.go
$(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

tools/smoke/grafana-agent-smoke: tools/smoke/main.go
$(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)



agent-image:
$(docker-build) -t $(IMAGE_PREFIX)/agent:$(IMAGE_BRANCH_TAG) -t $(IMAGE_PREFIX)/agent:$(IMAGE_TAG) -f cmd/agent/$(DOCKERFILE) .
agentctl-image:
$(docker-build) -t $(IMAGE_PREFIX)/agentctl:$(IMAGE_BRANCH_TAG) -t $(IMAGE_PREFIX)/agentctl:$(IMAGE_TAG) -f cmd/agentctl/$(DOCKERFILE) .
agent-operator-image:
$(docker-build) -t $(IMAGE_PREFIX)/agent-operator:$(IMAGE_BRANCH_TAG) -t $(IMAGE_PREFIX)/agent-operator:$(IMAGE_TAG) -f cmd/agent-operator/$(DOCKERFILE) .
grafana-agent-crow-image:
$(docker-build) -t $(IMAGE_PREFIX)/agent-crow:$(IMAGE_BRANCH_TAG) -t $(IMAGE_PREFIX)/agent-crow:$(IMAGE_TAG) -f cmd/grafana-agent-crow/$(DOCKERFILE) .
$(docker-build) -t $(INTERNAL_REGISTRY)/$(IMAGE_PREFIX)/agent-crow:$(IMAGE_BRANCH_TAG) -t $(INTERNAL_REGISTRY)/$(IMAGE_PREFIX)/agent-crow:$(IMAGE_TAG) -f tools/crow/$(DOCKERFILE) .
agent-smoke-image:
$(docker-build) -t $(INTERNAL_REGISTRY)/$(IMAGE_PREFIX)/agent-smoke:$(IMAGE_BRANCH_TAG) -t $(INTERNAL_REGISTRY)/$(IMAGE_PREFIX)/agent-smoke:$(IMAGE_TAG) -f tools/smoke/$(DOCKERFILE) .

install:
CGO_ENABLED=1 go install $(CGO_FLAGS) ./cmd/agent
CGO_ENABLED=0 go install $(GO_FLAGS) ./cmd/agentctl
CGO_ENABLED=0 go install $(GO_FLAGS) ./cmd/agent-operator
CGO_ENABLED=0 go install $(GO_FLAGS) ./cmd/grafana-agent-crow
CGO_ENABLED=0 go install $(GO_FLAGS) ./tools/crow
CGO_ENABLED=0 go install $(GO_FLAGS) ./tools/smoke

#######################
# Development targets #
Expand Down Expand Up @@ -306,7 +319,6 @@ endif
dist/agent-freebsd-amd64: seego
$(call SetBuildVarsConditional,freebsd); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent


#######################
# BEGIN AGENTCTL DIST #
#######################
Expand Down
4 changes: 2 additions & 2 deletions example/k3d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The smoke test environment is used to validate samples end to end.

Smoke Test environment is invoked via `/scripts/smoke-test.bash`

This tool will spin up cluster of Grafana Agent, Cortex, Avalanche and [Crow](../../cmd/grafana-agent-crow/README.md) instances. The tool will then periodically kill instances and check for any failed alerts. At the end of the duration (default 3h) it will end the testing.
This tool will spin up cluster of Grafana Agent, Cortex, Avalanche and [Crow](../../tools/crow/README.md) instances. The tool will then periodically kill instances and check for any failed alerts. At the end of the duration (default 3h) it will end the testing.

### What to look for?

Expand All @@ -70,7 +70,7 @@ If at the end of the test any issues are found they will look similar to the bel

### How to trigger an alert?

Changing the avalanche setting for label_count to 1000, located [here](./lib/avalanche/main.libsonnet). This will ensure the [GrafanaAgentMemHigh](http://prometheus.k3d.localhost:50080/graph?g0.expr=ALERTS%7Balertname%3D%22GrafanaAgentMemHigh%22%7D&g0.tab=1&g0.stacked=0&g0.show_exemplars=0.g0.range_input=1h.) alert exceeds the limit.
Changing the avalanche setting for label_count to 1000, located [here](../../production/tanka/grafana-agent/smoke/avalanche/main.libsonnet). This will ensure the [GrafanaAgentMemHigh](http://prometheus.k3d.localhost:50080/graph?g0.expr=ALERTS%7Balertname%3D%22GrafanaAgentMemHigh%22%7D&g0.tab=1&g0.stacked=0&g0.show_exemplars=0.g0.range_input=1h.) alert exceeds the limit.

![](./assets/trigger_change.png)

Expand Down
2 changes: 1 addition & 1 deletion example/k3d/environment/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local collector = import 'collector/main.libsonnet';
local default = import 'default/main.libsonnet';
local etcd = import 'etcd/main.libsonnet';
local etcd = import 'grafana-agent/smoke/etcd/main.libsonnet';
local agent_cluster = import 'grafana-agent/scraping-svc/main.libsonnet';
local k = import 'ksonnet-util/kausal.libsonnet';
local load_generator = import 'load-generator/main.libsonnet';
Expand Down
4 changes: 2 additions & 2 deletions example/k3d/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"subdir": "grafonnet"
}
},
"version": "0d4f64154ee2024820396aa66841a64d851302b0",
"sum": "1DvaFCCiwjI9624YYhLPdwiEPDvLsrCOES0aBxr7wrM="
"version": "3626fc4dc2326931c530861ac5bebe39444f6cbf",
"sum": "gF8foHByYcB25jcUOBqP6jxk0OPifQMjPvKY0HaCk6w="
},
{
"source": {
Expand Down
49 changes: 7 additions & 42 deletions example/k3d/scripts/smoke-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ set -euo pipefail
# Constants
ROOT=$(git rev-parse --show-toplevel)
K3D_CLUSTER_NAME="agent-smoke-test"
MUTATION_FREQUENCY="5m"
CHAOS_FREQUENCY="30m"
SKIP_CREATE=""

# Variables

# Which function will be called
ENTRYPOINT="run"
TEST_DURATION="3h"
TEST_DURATION="10800"
IMPORT_IMAGES=""

while getopts "dt:ish" opt; do
Expand Down Expand Up @@ -85,18 +84,13 @@ run() {
k3d image import -c $K3D_CLUSTER_NAME \
grafana/agent:main \
grafana/agentctl:main \
grafana/agent-crow:main
us.gcr.io/kubernetes-dev/grafana/agent-crow:main \
us.gcr.io/kubernetes-dev/grafana/agent-smoke:main
fi

(cd $ROOT/example/k3d && jb install)
tk apply $ROOT/example/k3d/smoke --dangerous-auto-approve

echo "--- Spawning background tasks"
mutation_loop &
MUTATION_PID=$!
chaos_loop &
CHAOS_PID=$!

# Immediately create a job to sync configs so our two Agent deployments
# are synced up as closely as possible.
kubectl --context=k3d-$K3D_CLUSTER_NAME --namespace=smoke \
Expand All @@ -106,10 +100,11 @@ run() {
echo "Your environment is now running for the next $TEST_DURATION."
echo "Grafana URL: http://grafana.k3d.localhost:50080"
echo "Prometheus URL: http://prometheus.k3d.localhost:50080"
echo "Check smoke test logs: "
echo " kubectl logs --namespace=smoke -f deployment/smoke-test"
sleep $TEST_DURATION

echo "--- Stopping background tasks"
kill $CHAOS_PID $MUTATION_PID
kubectl scale -n smoke --replicas=0 deployment/smoke-test

echo "Smoke tests complete!"
echo "Grafana URL: http://grafana.k3d.localhost:50080"
Expand All @@ -120,43 +115,13 @@ run() {
get_results
}

# mutation_loop changes the number of replicas of Avalanche servers
# randomly between 0-10 replicas (inclusive) every $MUTATION_FREQUENCY.
mutation_loop() {
while true; do
sleep $MUTATION_FREQUENCY

NEW_REPLICAS=$(($RANDOM % 11))
echo "--- Scaling Avalanche to $NEW_REPLICAS replicas"
kubectl --context=k3d-$K3D_CLUSTER_NAME --namespace=smoke \
scale --replicas=$NEW_REPLICAS deployment/avalanche
done
}

# chaos loop deletes pods every $CHAOS_FREQUENCY.
chaos_loop() {
while true; do
sleep $CHAOS_FREQUENCY

echo "--- Force deleting pod/grafana-agent-0"
kubectl --context=k3d-$K3D_CLUSTER_NAME --namespace=smoke \
delete --grace-period=0 --force pod/grafana-agent-0

REPLICA=$(($RANDOM % 3))
echo "--- Force deleting pod/agent-cluster-$REPLICA"
kubectl --context=k3d-$K3D_CLUSTER_NAME --namespace=smoke \
delete --grace-period=0 --force pod/grafana-agent-cluster-$REPLICA
done
}

get_results() {
NUM_ALERTS=$(curl -s -G \
-H "Host: prometheus.k3d.localhost" \
-d "query=count_over_time(ALERTS{alertstate=\"firing\"}[$TEST_DURATION])" \
'http://localhost:50080/api/v1/query' \
| jq '.data.result | length' \
)

if test $NUM_ALERTS -ne 0; then
echo "FAIL: $NUM_ALERTS alerts found over the last $TEST_DURATION."
echo "More information: http://prometheus.k3d.localhost:50080/graph?g0.expr=count_over_time(ALERTS{alertstate%3D%22firing%22}[$TEST_DURATION])"
Expand Down
13 changes: 10 additions & 3 deletions example/k3d/smoke/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
local monitoring = import './monitoring/main.jsonnet';
local avalanche = import 'avalanche/main.libsonnet';
local avalanche = import 'grafana-agent/smoke/avalanche/main.libsonnet';
local cortex = import 'cortex/main.libsonnet';
local crow = import 'crow/main.libsonnet';
local etcd = import 'etcd/main.libsonnet';
local crow = import 'grafana-agent/smoke/crow/main.libsonnet';
local smoke = import 'grafana-agent/smoke/main.libsonnet';
local etcd = import 'grafana-agent/smoke/etcd/main.libsonnet';
local gragent = import 'grafana-agent/v2/main.libsonnet';
local k = import 'ksonnet-util/kausal.libsonnet';

Expand All @@ -13,6 +14,7 @@ local volumeMount = k.core.v1.volumeMount;
local images = {
agent: 'grafana/agent:main',
agentctl: 'grafana/agentctl:main',
agentsmoke: 'us.gcr.io/kubernetes-dev/grafana/agent-smoke:main',
};

local new_crow(name, selector) =
Expand All @@ -23,6 +25,9 @@ local new_crow(name, selector) =
},
});

local new_smoke(name) = smoke.new(name, namespace='smoke',
mutationFrequency='5m', chaosFrequency='30m', image=images.agentsmoke);

local smoke = {
ns: namespace.new('smoke'),

Expand All @@ -39,6 +44,8 @@ local smoke = {
metric_interval: 600,
}),

smoke_test: new_smoke('smoke-test'),

crows: [
new_crow('crow-single', 'cluster="grafana-agent"'),
new_crow('crow-cluster', 'cluster="grafana-agent-cluster"'),
Expand Down
3 changes: 2 additions & 1 deletion example/k3d/smoke/monitoring/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ local ingress = k.networking.v1beta1.ingress;
local rule = k.networking.v1beta1.ingressRule;
local path = k.networking.v1beta1.httpIngressPath;

local prometheus_monitoring = import './prometheus_monitoring.libsonnet';

local prometheus_monitoring = import 'grafana-agent/smoke/prometheus_monitoring.libsonnet';

{
ns: namespace.new('monitoring'),
Expand Down
17 changes: 16 additions & 1 deletion pkg/util/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ func NewLogger(cfg *server.Config) *Logger {
return newLogger(cfg, defaultLogger)
}

// NewLoggerFromLevel creates a new logger from logging.Level and logging.Format.
func NewLoggerFromLevel(lvl logging.Level, fmt logging.Format) *Logger {
logger, err := makeDefaultLogger(lvl, fmt)
if err != nil {
panic(err)
}
return &Logger{
l: logger,
}
}

func newLogger(cfg *server.Config, ctor func(*server.Config) (log.Logger, error)) *Logger {
l := Logger{makeLogger: ctor}
if err := l.ApplyConfig(cfg); err != nil {
Expand All @@ -52,9 +63,13 @@ func (l *Logger) ApplyConfig(cfg *server.Config) error {
}

func defaultLogger(cfg *server.Config) (log.Logger, error) {
return makeDefaultLogger(cfg.LogLevel, cfg.LogFormat)
}

func makeDefaultLogger(lvl logging.Level, fmt logging.Format) (log.Logger, error) {
var l log.Logger

l, err := cortex_log.NewPrometheusLogger(cfg.LogLevel, cfg.LogFormat)
l, err := cortex_log.NewPrometheusLogger(lvl, fmt)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local volume = k.core.v1.volume;
local this = self,

_config+:: {
image: 'grafana/agent-crow:latest',
image: 'us.gcr.io/kubernetes-dev/grafana/agent-crow:main',
args: {},
} + config,

Expand Down
37 changes: 37 additions & 0 deletions production/tanka/grafana-agent/smoke/internal/smoke.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local k = import 'ksonnet-util/kausal.libsonnet';

local policyRule = k.rbac.v1.policyRule;
local serviceAccount = k.core.v1.serviceAccount;
local container = k.core.v1.container;
local deployment = k.apps.v1.deployment;

{
newSmoke(name='grafana-agent-smoke', namespace='default', mutationFrequency='5m', chaosFrequency='30m', image):: {
local k = (import 'ksonnet-util/kausal.libsonnet') { _config+:: { namespace: namespace } },

rbac:
k.util.rbac(name, [
policyRule.withApiGroups(['apps']) +
policyRule.withResources(['deployments/scale']) +
policyRule.withVerbs(['get', 'update']),
]) {
service_account+:
serviceAccount.mixin.metadata.withNamespace(namespace),
},

container::
container.new('agent-smoke', image) +
container.withCommand('/bin/grafana-agent-smoke') +
container.withArgsMixin(k.util.mapToFlags({
'log.level': 'debug',
'namespace': namespace,
'mutation-frequency': mutationFrequency,
'chaos-frequency': chaosFrequency,
})),

agentsmoke:
deployment.new(name, 1, [self.container]) +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.spec.template.spec.withServiceAccount(name),
},
}
14 changes: 14 additions & 0 deletions production/tanka/grafana-agent/smoke/main.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local smoke = import './internal/smoke.libsonnet';

{
_images:: {
agentsmoke: 'us.gcr.io/kubernetes-dev/grafana/agent-smoke:latest',
},

new(name='grafana-agent-smoke', namespace='grafana-agent-smoke', mutationFrequency='5m', chaosFrequency='30m', image=self._images.agentsmoke):: {
smoke:
smoke.newSmoke(name, namespace, mutationFrequency, chaosFrequency, image)
},

monitoring: (import './prometheus_monitoring.libsonnet'),
}
1 change: 1 addition & 0 deletions tools/crow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grafana-agent-crow
Loading