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

Commit

Permalink
Merge pull request #28 from rabbitmq/metrics-aggregation
Browse files Browse the repository at this point in the history
Option to aggregate channel, queue and connection metrics

(cherry picked from commit 82fafae)
  • Loading branch information
gerhard committed Feb 5, 2020
1 parent fe3c860 commit 5e794d4
Show file tree
Hide file tree
Showing 33 changed files with 1,427 additions and 134 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Expand Up @@ -24,11 +24,11 @@ ENV OPENSSL_SOURCE_SHA256="1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30
# https://www.openssl.org/community/omc.html
ENV OPENSSL_PGP_KEY_IDS="0x8657ABB260F056B1E5190839D9C4D26D0E604491 0x5B2545DAB21995F4088CEFAA36CEE4DEB00CFE33 0xED230BEC4D4F2518B9D7DF41F0DB4D21C1D35231 0xC1F33DD8CE1D4CC613AF14DA9195C48241FBF7DD 0x7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C 0xE5E52560DD91C556DDBDA5D02064C53641C25E5D"

# Use the latest stable Erlang/OTP release - gmake find-latest-otp - https://github.com/erlang/otp/tags
ENV OTP_VERSION 22.2.4
# TODO add PGP checking when the feature will be added to Erlang/OTP's build system
# http://erlang.org/pipermail/erlang-questions/2019-January/097067.html
ENV OTP_SOURCE_SHA256="7aab2285b46462332a7fdad395d4629e6465d5da324cf7e081e8d62fdb5b38f1"
# Use the latest stable Erlang/OTP release - make find-latest-otp - https://github.com/erlang/otp/tags
ARG OTP_VERSION
ENV OTP_VERSION ${OTP_VERSION}
ARG OTP_SHA256
ENV OTP_SOURCE_SHA256=${OTP_SHA256}

# Install dependencies required to build Erlang/OTP from source
# http://erlang.org/doc/installation_guide/INSTALL.html
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Expand Up @@ -5,6 +5,15 @@ DOCKER_IMAGE_NAME := pivotalrabbitmq/rabbitmq-prometheus
DOCKER_IMAGE_VERSION := $(BASED_ON_RABBITMQ_VERSION)-$(TODAY)
# RABBITMQ_VERSION is used in rabbitmq-components.mk to set PROJECT_VERSION
RABBITMQ_VERSION ?= $(DOCKER_IMAGE_VERSION)
# make find-latest-otp
OTP_VERSION := 22.2.5
OTP_SHA256 := a2359af240c7f629a4f9f19a9c0ba94e6ba024ed9fc4728c8ae55ea7c8c0e260

define PROJECT_ENV
[
{enable_metric_aggregation, false}
]
endef

PROJECT := rabbitmq_prometheus
PROJECT_MOD := rabbit_prometheus_app
Expand Down Expand Up @@ -95,6 +104,8 @@ di: docker-image
docker-image-build: ## dib | Build Docker image locally - make tests
@docker build --pull \
--build-arg PGP_KEYSERVER=pgpkeys.uk \
--build-arg OTP_VERSION=$(OTP_VERSION) \
--build-arg OTP_SHA256=$(OTP_SHA256) \
--build-arg RABBITMQ_VERSION=$(BASED_ON_RABBITMQ_VERSION) \
--build-arg RABBITMQ_PROMETHEUS_VERSION=$(RABBITMQ_VERSION) \
--tag $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION) \
Expand Down
12 changes: 12 additions & 0 deletions docker/docker-compose-overview.yml
Expand Up @@ -168,3 +168,15 @@ services:
CONSUMERS: 0
SERVERS_STARTUP_TIMEOUT: *startup_timeout
METRICS_PROMETHEUS: "true"
# many-queues:
# image: *perf-test-image
# networks:
# - "rabbitmq-prometheus"
# environment:
# URI: "amqp://guest:guest@rmq1:5672/%2f"
# QUEUE_PATTERN: "mq%d"
# QUEUE_PATTERN_FROM: 1
# QUEUE_PATTERN_TO: 1000
# RATE: 1
# SERVERS_STARTUP_TIMEOUT: *startup_timeout
# METRICS_PROMETHEUS: "true"
3 changes: 3 additions & 0 deletions k8s/.autocomplete
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

eval "$(make autocomplete)"
1 change: 1 addition & 0 deletions k8s/.envrc
@@ -0,0 +1 @@
PATH_add bin
4 changes: 4 additions & 0 deletions k8s/.gitignore
@@ -0,0 +1,4 @@
bin/*
*.pem
_manifest.yaml
.erlang.cookie
119 changes: 119 additions & 0 deletions k8s/Makefile
@@ -0,0 +1,119 @@
SHELL := bash# we want bash behaviour in all shell invocations
GCP_PROJECT := cf-rabbitmq-for-k8s-bunny
GCLOUD_CONFIG := rmq-for-k8s
GKE_CLUSTER := gerhard-2020-01-16
GKE_ZONE := europe-west2-b
GKE_VERSION := 1.16

LOCAL_BIN := $(CURDIR)/bin
PATH := $(LOCAL_BIN):$(PATH)
export PATH

.DEFAULT_GOAL := help
.PHONY: help
help:
@awk -F"[:#]" '/^[^\.][a-zA-Z\._\-]+:+.+##.+$$/ { printf "\033[36m%-24s\033[0m %s\n", $$1, $$4 }' $(MAKEFILE_LIST) \
| sort

define MAKE_TARGETS
awk -F: '/^[^\.%\t][a-zA-Z\._\-]*:+.*$$/ { printf "%s\n", $$1 }' $(MAKEFILE_LIST)
endef
define BASH_AUTOCOMPLETE
complete -W \"$$($(MAKE_TARGETS) | sort | uniq)\" make gmake m
endef
.PHONY: autocomplete
autocomplete:
@echo "$(BASH_AUTOCOMPLETE)"
.PHONY: ac
ac: autocomplete

# Do not use kubectl installed by Docker for Desktop, this will typically be an older version than kubernetes-cli
KUBECTL := $(lastword /usr/local/Cellar/kubernetes-cli/$(GKE_VERSION).0/bin/kubectl $(wildcard /usr/local/Cellar/kubernetes-cli/*/bin/kubectl))
$(KUBECTL):
brew install kubernetes-cli
bin/kubectl: $(KUBECTL) ## Setup kubectl CLI
mkdir -p $(LOCAL_BIN) \
&& ln -sf $(KUBECTL) $(LOCAL_BIN)/kubectl

HELM := /usr/local/opt/helm@2/bin/helm
$(HELM):
brew install helm@2
bin/helm: $(HELM) ## Setup helm CLI
mkdir -p $(LOCAL_BIN) \
&& ln -sf $(HELM) $(LOCAL_BIN)/helm

LPASS := /usr/local/bin/lpass
$(LPASS):
brew install lastpass-cli

.PHONY: gcloud-login
gcloud-login: ## Login gcloud CLI
gcloud config configurations activate $(GCLOUD_CONFIG) \
|| gcloud config configurations create $(GCLOUD_CONFIG)
gcloud auth login
gcloud config set project $(GCP_PROJECT)

.PHONY: gke-ls
gke-ls: ## List GKE clusters
gcloud container clusters list

.PHONY: gke-connect
gke-connect: ## Connect kubectl to GKE cluster
gcloud container clusters get-credentials $(GKE_CLUSTER) --zone $(GKE_ZONE)

.PHONY: gke-admin
gke-admin: $(KUBECTL)
$(KUBECTL) apply --filename config/cluster-admin.yaml

.PHONY: haproxy
haproxy: config/haproxy/dhparams.pem config/haproxy/ca.pem config/haproxy/bundle.pem $(HELM) $(KUBECTL)
cd config/haproxy \
&& $(HELM) template . --name haproxy > _manifest.yaml \
&& $(KUBECTL) apply --filename _manifest.yaml

.PHONY: haproxy-delete
haproxy-delete: $(KUBECTL)
$(KUBECTL) delete -f config/haproxy/_manifest.yaml

config/haproxy/dhparams.pem:
openssl dhparam -out $(@) 2048

# https://support.cloudflare.com/hc/en-us/articles/115000479507
config/haproxy/ca.pem: $(LPASS)
$(LPASS) show --notes "Shared-RabbitMQ/cloudflare-origin-ca-rsa-root.pem" > $(@)

config/haproxy/bundle.pem: $(LPASS)
$(LPASS) show --notes "Shared-RabbitMQ/cloudflare-edge-bundle.pem" > $(@)

.PHONY: cluster-admin-binding
cluster-admin-binding: $(KUBECTL)
$(KUBECTL) get --filename config/cluster-admin.yaml \
|| $(KUBECTL) apply --filename config/cluster-admin.yaml

.PHONY: rabbitmq
rabbitmq: cluster-admin-binding config/agentmq/.erlang.cookie $(HELM) $(KUBECTL)
cd config/agentmq \
&& $(HELM) template . --name agentmq > _manifest.yaml \
&& $(KUBECTL) apply --filename _manifest.yaml

.PHONY: rabbitmq-delete
rabbitmq-delete: $(KUBECTL)
$(KUBECTL) delete -f config/agentmq/_manifest.yaml

.PHONY: rabbitmq-proxy
rabbitmq-proxy: $(KUBECTL)
$(KUBECTL) port-forward service/agentmq 15672:15672 15692:15692

config/agentmq/.erlang.cookie:
echo -n "$$(openssl rand -hex 10)" > $(@)

clean: haproxy-delete rabbitmq-delete

LIMIT ?= 20
events: $(KUBECTL)
$(KUBECTL) get events --sort-by='.metadata.creationTimestamp' | tail -n $(LIMIT)

resources: $(KUBECTL)
$(KUBECTL) get all -o wide
$(KUBECTL) get secret
$(KUBECTL) get configmap
5 changes: 5 additions & 0 deletions k8s/config/agentmq/Chart.yaml
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: agentmq
version: 0.1.1
87 changes: 87 additions & 0 deletions k8s/config/agentmq/README.md
@@ -0,0 +1,87 @@
## Agentmq

* all commands are assumed to be running from the example directory

All the main variables are in `values.yaml`. Changes should be made there.

### Install

Make sure we set the correct variables. The default values in `values.yaml` are for local.

```
helm install --name agentmq --namespace default -f values.yaml ../agentmq --set environment=dev --set key1=value1 --set key2=value2
```

Check all the things.

```
helm ls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
...omitted
agentmq 1 Thu Aug 23 15:17:37 2018 DEPLOYED agentmq-0.1.0 1.0 default
```

### Upgrading
```
helm upgrade -f values.yaml agentmq ../agentmq
```

### Delete chart

```
helm delete agentmq --purge
release "agentmq" deleted
```


### Testing locally

to test the template and install procedure without actually doing it.

```
helm install --dry-run --debug ../agentmq --set key1=var1
```

To just see the template

```
helm template -f values.yaml agentmq ../agentmq
```


## Configuration

The following table lists the configurable vales that can be used in a XXX-values.yaml file. If no value is specified, it will default to whatever is in the **values.yaml**



Parameter | Description | Default
--------- | ----------- | -------
`rabbitmqUsers` | list of rabbitmq users | `[]`
`serviceAccountName` | service account name | `agentmq`
`service.type` | Type of service to create [service](https://kubernetes.io/docs/concepts/services-networking/service/) | `NodePort`
`service.name` | service name [service](https://kubernetes.io/docs/concepts/services-networking/service/) | `agentmq`
`service.selector.name` | selector for service [service](https://kubernetes.io/docs/concepts/services-networking/service/) | `agentmq`
`image.tag` | Image tag [image](https://kubernetes.io/docs/concepts/containers/images/) | `test`
`image.repository` | Image repository [image](https://kubernetes.io/docs/concepts/containers/images/) | `automox/local/agentmq`
`replicaCount` | replicas to make | `1`
`containerPorts` | ports to expose on the container | `[]`
`environment` | local,dev,stg,prod | `local`
`serviceName` | name of agentmq service | `agentmq`
`affinity` | Node affinity | `{}`
`tolerations` | List of node taints to tolerate | `[]`
`nodeSelector` | Node to select | `{}`
`servicePorts` | service ports to expose | `[]`
`resources` | CPU/Memory resource requests/limits | `{}`
`name` | name of the pod/deployment | `agentmq`

## Exporter

A sidecar container is deployed that exports rabbitmq data for prometheus.

For detailed instructions, [check out the exporter](https://github.com/PatchSimple/rabbitmq-exporter)

It is mounted to /tmp/configs/config.yaml and _should_ be updated in real time.

**NOTE:** if the port is changed, the pod **needs** to be restarted to take effect. Idk how to solve this but if you do feel free!

32 changes: 32 additions & 0 deletions k8s/config/agentmq/templates/_helpers.tpl
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "agentmq.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "agentmq.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "agentmq.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

0 comments on commit 5e794d4

Please sign in to comment.