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

build from source #63

Closed
fedya opened this issue Nov 6, 2018 · 27 comments
Closed

build from source #63

fedya opened this issue Nov 6, 2018 · 27 comments

Comments

@fedya
Copy link

fedya commented Nov 6, 2018

Please provide some guide to build project from sources

@deadtrickster
Copy link
Owner

This builds like any other rabbitmq plugin. Have you tried it?

@fedya
Copy link
Author

fedya commented Nov 6, 2018

Yes, tried

make[2]: Entering directory `/root/rabbitmq-server/BUILD/rabbitmq-server-3.7.7/deps/prometheus_rabbitmq_exporter/deps/rabbit_common'
erlang.mk:30: Please upgrade to GNU Make 4 or later: https://erlang.mk/guide/installation.html
 DEP    rabbitmq_codegen
 DEP    lager
 DEP    jsx
 DEP    ranch_proxy_protocol
 DEP    recon
make[2]: *** No rule to make target `/root/rabbitmq-server/BUILD/rabbitmq-server-3.7.7/deps/prometheus_rabbitmq_exporter/deps/rabbitmq_codegen/amqp_codegen.py', needed by `include/rabbit_framing.hrl'.  Stop.
make[2]: *** Waiting for unfinished jobs....

@gerhard
Copy link
Contributor

gerhard commented Feb 13, 2019

I need to build a custom version to test dcorbacho@db4762d but can't remember how to build this 🤔

git clone https://github.com/dcorbacho/prometheus_rabbitmq_exporter
cd prometheus_rabbitmq_exporter
git checkout core-metrics-exporter
make all RABBITMQ_VERSION=3.7.11 RABBITMQ_CURRENT_FETCH_URL=https://github.com/rabbitmq/
???

@gerhard
Copy link
Contributor

gerhard commented Feb 13, 2019

With some help from @acogoluegnes, we've concluded that it's just a matter of zipping ebin include priv dirs into e.g. prometheus_rabbitmq_exporter-3.7.20190213.ez

@deadtrickster do you want me to wrap this into a make ez and submit a PR?

@deadtrickster
Copy link
Owner

deadtrickster commented Feb 13, 2019

make all RABBITMQ_VERSION=3.7.11 RABBITMQ_CURRENT_FETCH_URL=https://github.com/rabbitmq/

ugh never knew about these vars, I usually check-out tags.

do you want me to wrap this into a make ez and submit a PR?

Yeah, would be nice. When I want to update deps (like prometheus.erl, accept, etc) I use https://github.com/deadtrickster/rebar3_archive_plugin. Maybe this could help.

@gerhard
Copy link
Contributor

gerhard commented Feb 13, 2019

I am yet to test the resulting ez, but I'm attaching the diff that made possible to just make ez

You will notice in the diff that I removed the prometheus_process_collector dep. It was failing because rebar3_archive_plugin is missing. After I've added it, I had to add rebar3_elvis_plugin, and after that the new dependencies. Things were still failing so I just gave up digging and removed prometheus_process_collector. After deadtrickster/prometheus_process_collector#9, and considering that prometheus_process_collector only works on Linux because NIF, we are not friends.

These changes enabled me to create prometheus_rabbitmq_exporter-3.7.20190213.ez that I can now test:

diff --git a/.gitignore b/.gitignore
index 9953f1e..db249c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@
 
 /rabbitmq_management_metrics.d
 erl_crash.dump
+*.ez
diff --git a/Makefile b/Makefile
index a2d7610..71802e4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,22 @@
 PROJECT = prometheus_rabbitmq_exporter
+PROJECT_DESCRIPTION = RabbitMQ Prometheus.io metrics exporter
+RABBITMQ_VERSION = 3.7.$(shell date +'%Y%m%d')
+# PROJECT_VERSION gets set in rabbitmq-components.mk to RABBITMQ_VERSION
+EZ = $(PROJECT)-$(PROJECT_VERSION)
+PROJECT_APP_EXTRA_KEYS = {maintainers, ["Ilya Khaprov"]}, \
+  {licenses, ["MIT"]}, \
+  {links, [{"Github", "https://github.com/deadtrickster/prometheus_rabbitmq_exporter"}]}
 
-dep_prometheus = hex 3.5.1
-dep_prometheus_process_collector = hex 1.3.1
-dep_prometheus_httpd = hex 2.1.8
 dep_accept = hex 0.3.3
+dep_prometheus = hex 3.5.1
 dep_prometheus_cowboy = hex 0.1.4
+dep_prometheus_httpd = hex 2.1.8
+
+DEPS = rabbit rabbitmq_management  \
+       prometheus prometheus_cowboy prometheus_httpd
 
-DEPS = rabbit_common rabbit rabbitmq_management prometheus prometheus_httpd accept \
-	prometheus_process_collector prometheus_cowboy
+# We do not want these deps defined as applications in app
+BUILD_DEPS = rabbit_common rabbitmq_management_agent accept
 
 DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
 DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
@@ -18,10 +27,13 @@ DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
 ERLANG_MK_REPO = https://github.com/rabbitmq/erlang.mk.git
 ERLANG_MK_COMMIT = rabbitmq-tmp
 
+RABBITMQ_BRANCH ?= v3.7.x
+RABBITMQ_CURRENT_FETCH_URL ?= https://github.com/rabbitmq/
+
 include rabbitmq-components.mk
 include erlang.mk
 
-.PHONY: docker_build docker_push docker_latest docker_pure docker_alpine
+.PHONY: up docker_build docker_push docker_latest docker_pure docker_alpine
 
 docker_build:
 	docker build -t deadtrickster/rabbitmq_prometheus\:3.7.8 .
@@ -47,3 +59,28 @@ docker_pure:
 
 docker_alpine:
 	-docker run -p15672\:15672 deadtrickster/rabbitmq_prometheus\:latest-alpine
+
+up: $(abspath .)+up $(DEPS:%=$(DEPS_DIR)/%+up) $(BUILD_DEPS:%=$(DEPS_DIR)/%+up)
+	@:
+
+%+up: fetch-deps
+	$(exec_verbose) cd $*; \
+	git fetch -p && \
+	if [ '$(RABBITMQ_BRANCH)' ]; then \
+		git checkout $(RABBITMQ_BRANCH) || : ; \
+	fi && \
+	if git symbolic-ref -q HEAD >/dev/null; then \
+		branch=$$(git symbolic-ref --short HEAD); \
+		remote=$$(git config branch.$$branch.remote); \
+		merge=$$(git config branch.$$branch.merge | sed 's,refs/heads/,,'); \
+		if [ "$$remote" -a "$$merge" ]; then \
+			git merge --ff-only "$$remote/$$merge"; \
+		fi; \
+	fi && \
+	echo
+
+ez: up all
+	@rm -fr $(EZ) && mkdir $(EZ) && \
+	cp -r ebin include priv $(EZ) && \
+	rm -f $(EZ).ez && \
+	zip --move --recurse-paths --test $(EZ).ez $(EZ)
diff --git a/rabbitmq-components.mk b/rabbitmq-components.mk
index 6d4d9c9..0789b1c 100644
--- a/rabbitmq-components.mk
+++ b/rabbitmq-components.mk
@@ -40,7 +40,6 @@ endif
 dep_amqp_client                       = git_rmq rabbitmq-erlang-client $(current_rmq_ref) $(base_rmq_ref) master
 dep_amqp10_client                     = git_rmq rabbitmq-amqp1.0-client $(current_rmq_ref) $(base_rmq_ref) master
 dep_amqp10_common                     = git_rmq rabbitmq-amqp1.0-common $(current_rmq_ref) $(base_rmq_ref) master
-dep_ra                                = git_rmq ra $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbit                            = git_rmq rabbitmq-server $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbit_common                     = git_rmq rabbitmq-common $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_amqp1_0                  = git_rmq rabbitmq-amqp1.0 $(current_rmq_ref) $(base_rmq_ref) master
@@ -51,7 +50,6 @@ dep_rabbitmq_auth_backend_ldap        = git_rmq rabbitmq-auth-backend-ldap $(cur
 dep_rabbitmq_auth_mechanism_ssl       = git_rmq rabbitmq-auth-mechanism-ssl $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_aws                      = git_rmq rabbitmq-aws $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_boot_steps_visualiser    = git_rmq rabbitmq-boot-steps-visualiser $(current_rmq_ref) $(base_rmq_ref) master
-dep_rabbitmq_clusterer                = git_rmq rabbitmq-clusterer $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_cli                      = git_rmq rabbitmq-cli $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_codegen                  = git_rmq rabbitmq-codegen $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_consistent_hash_exchange = git_rmq rabbitmq-consistent-hash-exchange $(current_rmq_ref) $(base_rmq_ref) master
@@ -71,7 +69,6 @@ dep_rabbitmq_management               = git_rmq rabbitmq-management $(current_rm
 dep_rabbitmq_management_agent         = git_rmq rabbitmq-management-agent $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_management_exchange      = git_rmq rabbitmq-management-exchange $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_management_themes        = git_rmq rabbitmq-management-themes $(current_rmq_ref) $(base_rmq_ref) master
-dep_rabbitmq_management_visualiser    = git_rmq rabbitmq-management-visualiser $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_message_timestamp        = git_rmq rabbitmq-message-timestamp $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_metronome                = git_rmq rabbitmq-metronome $(current_rmq_ref) $(base_rmq_ref) master
 dep_rabbitmq_mqtt                     = git_rmq rabbitmq-mqtt $(current_rmq_ref) $(base_rmq_ref) master
@@ -111,20 +108,18 @@ dep_rabbitmq_public_umbrella          = git_rmq rabbitmq-public-umbrella $(curre
 # all projects use the same versions. It avoids conflicts and makes it
 # possible to work with rabbitmq-public-umbrella.
 
-dep_cowboy = hex 2.2.2
-dep_cowlib = hex 2.1.0
-dep_jsx = hex 2.8.2
-dep_lager = hex 3.6.3
-dep_ranch = hex 1.5.0
-dep_ranch_proxy_protocol = hex 1.5.0
-dep_recon = hex 2.3.2
-
-dep_sockjs = git https://github.com/rabbitmq/sockjs-erlang.git 405990ea62353d98d36dbf5e1e64942d9b0a1daf
+dep_cowboy = hex 2.6.1
+dep_cowlib = hex 2.7.0
+dep_jsx = hex 2.9.0
+dep_lager = hex 3.6.5
+dep_ra = git https://github.com/rabbitmq/ra.git master
+dep_ranch = hex 1.7.1
+dep_recon = hex 2.3.6
+dep_sysmon_handler = hex 1.1.0
 
 RABBITMQ_COMPONENTS = amqp_client \
 		      amqp10_common \
 		      amqp10_client \
-		      ra \
 		      rabbit \
 		      rabbit_common \
 		      rabbitmq_amqp1_0 \
@@ -135,7 +130,6 @@ RABBITMQ_COMPONENTS = amqp_client \
 		      rabbitmq_auth_mechanism_ssl \
 		      rabbitmq_aws \
 		      rabbitmq_boot_steps_visualiser \
-		      rabbitmq_clusterer \
 		      rabbitmq_cli \
 		      rabbitmq_codegen \
 		      rabbitmq_consistent_hash_exchange \
@@ -155,7 +149,6 @@ RABBITMQ_COMPONENTS = amqp_client \
 		      rabbitmq_management_agent \
 		      rabbitmq_management_exchange \
 		      rabbitmq_management_themes \
-		      rabbitmq_management_visualiser \
 		      rabbitmq_message_timestamp \
 		      rabbitmq_metronome \
 		      rabbitmq_mqtt \
@@ -233,7 +226,7 @@ export base_rmq_ref
 # If cloning from this computed location fails, we fallback to RabbitMQ
 # upstream which is GitHub.
 
-# Maccro to transform eg. "rabbit_common" to "rabbitmq-common".
+# Macro to transform eg. "rabbit_common" to "rabbitmq-common".
 rmq_cmp_repo_name = $(word 2,$(dep_$(1)))
 
 # Upstream URL for the current project.
diff --git a/src/prometheus_rabbitmq_exporter.app.src b/src/prometheus_rabbitmq_exporter.app.src
deleted file mode 100644
index 3a79b6c..0000000
--- a/src/prometheus_rabbitmq_exporter.app.src
+++ /dev/null
@@ -1,19 +0,0 @@
-{application, prometheus_rabbitmq_exporter,
- [{description, "RabbitMQ Prometheus.io metrics exporter"},
-  %% 3.7.2 or newer 3.7.x
-  %% {broker_version_requirements, ["3.7.2"]},
-  {vsn, "3.7.2.4"},
-  {modules, []},
-  {registered, []},
-  {env, []},
-  {applications, [kernel,
-                  stdlib,
-                  rabbit,
-                  rabbitmq_management,
-                  prometheus,
-                  prometheus_cowboy,
-                  prometheus_httpd]},
-
-  {maintainers, ["Ilya Khaprov"]},
-  {licenses, ["MIT"]},
-  {links, [{"Github", "https://github.com/deadtrickster/prometheus_rabbitmq_exporter"}]}]}.

@deadtrickster
Copy link
Owner

I'm ok removing process_collector. Classic, but I don't have any problems with it :-(. Still will be including it in releasing anyway.

@gerhard
Copy link
Contributor

gerhard commented Feb 18, 2019

The resulting .ez works as expected, I am now figuring out how to integrate this with rebar3 & rebar3_archive_plugin. I will spend a bit more time getting process_collector to work as well.

I will be done when all ez files can be built from within this plugin with a single command: make ez

@deadtrickster
Copy link
Owner

btw any plans to have a PR for that Core metrics exporter?

@gerhard
Copy link
Contributor

gerhard commented Feb 19, 2019

I've managed to build prometheus_process_collector as well as all other dependencies. Will wrap the code in a PR as soon as I get a minute.

@gerhard
Copy link
Contributor

gerhard commented Feb 19, 2019

btw any plans to have a PR for that Core metrics exporter?

That was the initial plan, but we've discovered that core metrics don't need rabbitmq_management, they simply read ETS. @dcorbacho is entertaining the idea of a standalone plugin. I'm curious to see how this plays out, but the alternative of not using the API to collect metrics is too good to not explore thoroughly.

@gerhard
Copy link
Contributor

gerhard commented Feb 19, 2019

I've started pushing changes required in different deps to make this come together. I have noticed that prometheus_rabbitmq_exporter is using prometheus.erl v3.5.1, yet the latest is v4.2.2. Is there anything keeping prometheus_rabbitmq_exporter pinned to prometheus.erl v3.x?

@gerhard
Copy link
Contributor

gerhard commented Feb 19, 2019

I can see that https://github.com/deadtrickster/prometheus_process_collector/tree/v1.4.0 already has the rebar3_archive_plugin deps. Is there any reason why prometheus_rabbitmq_exporter can't use this version? It's currently referencing prometheus_process_collector v1.3.1.

@gerhard
Copy link
Contributor

gerhard commented Feb 19, 2019

This is something new that I've just started hitting. @deadtrickster have you seen this before?

~/github.com/dcorbacho/prometheus_rabbitmq_exporter ./rebar3 archive
===> Verifying dependencies...
===> Building archive...
escript: exception error: undefined function rebar3_archive_plugin:format_error/1
  in function  rebar3:handle_error/2 (/opt/rebar3-3.9.0/src/rebar3.erl, line 339)
  in call from escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1
  in call from init:do_boot/3

./rebar3 -v
rebar 3.9.0 on Erlang/OTP 21 Erts 10.1.1

Same rebar archiving accept:

~/github.com/dcorbacho/prometheus_rabbitmq_exporter/deps/accept ../../rebar3 archive
===> Verifying dependencies...
===> Compiling accept
===> Building archive...

ls -l accept-0.3.3.ez
-rw-r--r--  1 gerhard  staff  12600 19 Feb 18:10 accept-0.3.3.ez

date
Tue 19 Feb 2019 18:10:55 GMT

@deadtrickster
Copy link
Owner

deadtrickster commented Feb 20, 2019

Is there anything keeping prometheus_rabbitmq_exporter pinned to prometheus.erl v3.x?

OTP 19 support

Is there any reason why prometheus_rabbitmq_exporter can't use this version?

I'm not sure, I just tried 1.4.x works OK.

have you seen this before?

no :-) can you run it with DEBUG=1?

@michaelklishin
Copy link
Contributor

michaelklishin commented Feb 20, 2019

It's time for this and related plugins to maintain two release branches, much like RabbitMQ does. RabbitMQ master requires OTP 21.2, v3.7.x requires 20.3.

I don't see any reasons for new releases to cling on OTP 19 but if @deadtrickster would like to support it, it should be on a separate branch (and release series).

@deadtrickster
Copy link
Owner

nah, I'll happily abandon otp19 and move prometheus to 4.x here

@gerhard
Copy link
Contributor

gerhard commented Feb 20, 2019

OK, bumping to prometheus.erl v4.2.2

prometheus_cowboy v0.1.6 fails to archive:

deps/prometheus_cowboy DEBUG=1 ../../rebar3 archive
===> Expanded command sequence to be run: [{default,app_discovery},
                                                  {default,install_deps},
                                                  {default,lock},
                                                  {default,compile},
                                                  {default,archive}]
===> Provider: {default,app_discovery}
===> Provider: {default,install_deps}
===> Verifying dependencies...
===> Dep prometheus has invalid version ~> 3.5 or ~> 4.2

This is what I get with DEBUG=1. The way I read the error, rebar3 wants to handle_error/2 but rebar3_archive_plugin does not implement format_error/1. Could this be an incompatibility between rebar3_archive_plugin v0.0.1 & rebar v3.9.0 ?

DEBUG=1 ./rebar3 archive
===> Expanded command sequence to be run: [{default,app_discovery},
                                                  {default,install_deps},
                                                  {default,lock},
                                                  {default,compile},
                                                  {default,archive}]
===> Provider: {default,app_discovery}
===> Provider: {default,install_deps}
===> Verifying dependencies...
===> Provider: {default,lock}
===> Provider: {default,compile}
===> run_hooks("/Users/gerhard/github.com/dcorbacho/prometheus_rabbitmq_exporter", pre_hooks, compile) -> no hooks defined

===> run_hooks("/Users/gerhard/github.com/dcorbacho/prometheus_rabbitmq_exporter", post_hooks, compile) -> no hooks defined

===> Provider: {default,archive}
===> run_hooks("/Users/gerhard/github.com/dcorbacho/prometheus_rabbitmq_exporter", pre_hooks, archive) -> no hooks defined

===> Building archive...
===> run_hooks("/Users/gerhard/github.com/dcorbacho/prometheus_rabbitmq_exporter", post_hooks, archive) -> no hooks defined

escript: exception error: undefined function rebar3_archive_plugin:format_error/1
  in function  rebar3:handle_error/2 (/opt/rebar3-3.9.0/src/rebar3.erl, line 339)
  in call from escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1
  in call from init:do_boot/3

@deadtrickster
Copy link
Owner

I just published prometheus_cowboy 0.1.7. Turns out rebar3 doesn't play well with this hex.pm version metadata

@deadtrickster
Copy link
Owner

published archive plugin with the callback

@deadtrickster
Copy link
Owner

So I guess we have the answer for this now. Closing. Thanks @gerhard!

Still, would be nice to have dcorbacho@db4762d

@gerhard
Copy link
Contributor

gerhard commented Feb 27, 2019

Still, would be nice to have dcorbacho@db4762d

Will submit as is, even though we've discovered 2 important aspects that we would like to address soon-ish:

  1. Core metrics don't require rabbitmq_management, but prometheus_rabbitmq_exporter does. Collecting metrics via rabbitmq_management puts extra pressure on the cluster, which can be detrimental in scenarios with many objects. The long-term goal is to stop using management for metrics, and keep it just for management tasks.
  2. Core metrics are per node, prometheus_rabbitmq_exporter exposes a combination of node & cluster metrics. Prometheus expects every target to return its own metrics, so the fact that we are returning aggregated (cluster) metrics is not just confusing, but it also puts extra pressure on RabbitMQ (scatter/gather from all nodes then aggregate) & duplicates metrics (same number of cluster channels from all nodes).

Would it be hard to disable the dependency on rabbitmq_management and only enable the core metrics collector?

@deadtrickster
Copy link
Owner

Management used for getting metrics and exposing. Of course given prometheus_httpd we can expose even without it, using just inets.

I would be happy to switch to node-only metrics. I agree current mix is confusing. The only way to workaround it is to configure cluster-wide collectors on one node and disable them on others, leaving just beam/process.

@gerhard
Copy link
Contributor

gerhard commented Feb 27, 2019

I would be happy to switch to node-only metrics.

Yes please!

The only way to workaround it is to configure cluster-wide collectors on one node and disable them on others

Why would there be any cluster-wide collectors? The sum across all nodes of certain metrics (e.g. queues, connections, channels) are the total for the entire cluster. Other than users & exchanges, which are just data, everything else is per-node. Even vhosts, while they are the same across all nodes, the Erlang processes which represent them are per-node and we might want to capture extra metrics for them one day. I can't think of any reason why we would want cluster-wide collectors. Am I missing something? Do you want to weigh in @dcorbacho @michaelklishin @kjnilsson ?

@deadtrickster
Copy link
Owner

Why would there be any cluster-wide collectors?

Unless I'm completely off, I feel like some metrics are duplicated on all nodes, exactly because of management plugin or the way they aggregated. i think someone even complained about that. So I proposed workaround, which is of course just a hack and not really robust - collect replicated metrics only from one node.

@michaelklishin
Copy link
Contributor

But this is not a collection problem, it's an aggregation problem.

@kjnilsson
Copy link

If you can push the local metrics (core or "collected") and aggregate them outside of RabbitMQ that would be the ideal solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants