percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.18k stars 423 forks source link

Manual build of the exporter is failing with multiples errors for goreleaser. #890

Closed jenunes closed 2 weeks ago

jenunes commented 2 months ago

Describe the bug Having followed the documentation section here, a manual build of the exporter is not working as expected, mostly related to removed, incompatible parameters and unsupported versions to build it.

To Reproduce

  1. Download the repo (tested with 0.40.0 and main) :
    
    $ wget https://github.com/percona/mongodb_exporter/archive/refs/tags/v0.40.0.zip
    --2024-08-14 17:14:20--  https://github.com/percona/mongodb_exporter/archive/refs/tags/v0.40.0.zip
    Resolving github.com (github.com)... 20.201.28.151
    Connecting to github.com (github.com)|20.201.28.151|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://codeload.github.com/percona/mongodb_exporter/zip/refs/tags/v0.40.0 [following]
    --2024-08-14 17:14:20--  https://codeload.github.com/percona/mongodb_exporter/zip/refs/tags/v0.40.0
    Resolving codeload.github.com (codeload.github.com)... 20.201.28.149
    Connecting to codeload.github.com (codeload.github.com)|20.201.28.149|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: unspecified [application/zip]
    Saving to: ‘v0.40.0.zip’

v0.40.0.zip [ <=> ] 199,89K --.-KB/s in 0,08s

2024-08-14 17:14:21 (2,40 MB/s) - ‘v0.40.0.zip’ saved [204689]

2. Walk to mongodb_exporter directory and run the `make release` command: 

~/Downloads/mongodb_exporter-0.40.0$ make release docker run --rm --privileged \ -v /home/jean/Downloads/mongodb_exporter-0.40.0:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser release --snapshot --skip-publish --rm-dist ⨯ command failed error=unknown flag: --skip-publish make: *** [Makefile:77: release] Error 1

As we can see above, it doesn't know the option `--skip-publish`; if we check the goreleaser documentation:
- https://goreleaser.com/cmd/goreleaser_release/

That option and also  `--rm-dist`  does not exists anymore. The `--rm-dist` was replaced with `--clean`.

3. Manually modifying the Makefile to adjust that accordingly:

release: ## Build the binaries using goreleaser docker run --rm --privileged \ -v ${PWD}:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser release --snapshot --clean

We then fall into a different error:

~/Downloads/mongodb_exporter$ make release docker run --rm --privileged \ -v /home/jean/Downloads/mongodb_exporter-0.40.0:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser release --snapshot --clean • only configurations files on version: 2 are supported, yours is version: 0 , please update your configuration ⨯ release failed after 0s error=only configurations files on version: 2 are supported, yours is version: 0 , please update your configuration make: *** [Makefile:77: release] Error 1

Also from goreleaser doc:

- https://goreleaser.com/errors/version/

4. If we try to use `version: 2` for the .goreleaser.yml, it then  fails with field issues:

$ make release docker run --rm --privileged \ -v /home/jean/Downloads/mongodb_exporter-0.40.0:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser release --snapshot --clean ⨯ release failed after 0s error=yaml: unmarshal errors: line 29: field after not found in type config.Changelog line 92: field replacements not found in type config.NFPM make: *** [Makefile:77: release] Error 1

Which makes sense assuming the configurations weren't ready for `version: 2`.

5. If we then try to use a lower goreleaser version such as v[1.26.2](https://github.com/goreleaser/goreleaser/releases/tag/v1.26.2), it fails with another removed parameter:

~/Downloads/mongodb_exporter-0.40.0$ make release docker run --rm --privileged \ -v /home/jean/Downloads/mongodb_exporter-0.40.0:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser:v1.26.2 release --snapshot --skip-publish --rm-dist Flag --rm-dist has been deprecated, please use --clean instead • starting release... ⨯ release failed after 0s error=yaml: unmarshal errors: line 91: field replacements not found in type config.NFPM make: *** [Makefile:77: release] Error 1

From documentation:

- https://goreleaser.com/deprecations/#nfpmsreplacements

> _since 2022-11-24 (v1.14.0), removed 2023-06-06 (v1.19.0)_

6. If we go lower than that, v1.18.2; it then fails into issues on starting the container:

~/Downloads/mongodb_exporter-0.40.0$ make release docker run --rm --privileged \ -v /home/jean/Downloads/mongodb_exporter-0.40.0:/go/src/github.com/user/repo \ -w /go/src/github.com/user/repo \ goreleaser/goreleaser:v1.18.2 release --snapshot --clean • starting release... • loading config file file=.goreleaser.yml • loading environment variables • getting and validating git state • accepting to run without a git repository because this is a snapshot • building... commit=none latest tag=v0.0.0 • pipe skipped reason=disabled during snapshot mode • parsing tag • setting defaults • DEPRECATED: nfpms.replacements should not be used anymore, check https://goreleaser.com/deprecations#nfpmsreplacements for more info • snapshotting • building snapshot... version=none . . . • docker images • building docker image image=docker.io/percona/mongodb_exporter:0.0-arm64v8 • building docker image image=docker.io/percona/mongodb_exporter:0.0-amd64 ⨯ release failed after 22s error=docker build failed: failed to build docker.io/percona/mongodb_exporter:0.0-amd64: exit status 1: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Learn more at https://goreleaser.com/errors/docker-build

make: *** [Makefile:77: release] Error 1

Even though the user is part of the docker group and has the necessary permissions and docker is running.

~/Downloads/mongodb_exporter-0.40.0$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

~/Downloads/mongodb_exporter-0.40.0$ ps -ef | grep -i docker jean 519074 5238 0 17:03 ? 00:00:00 rootlesskit --state-dir=/run/user/1000/dockerd-rootless --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=builtin --copy-up=/etc --copy-up=/run --propagation=rslave /usr/bin/dockerd-rootless.sh jean 519087 519074 0 17:03 ? 00:00:00 /proc/self/exe --state-dir=/run/user/1000/dockerd-rootless --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=builtin --copy-up=/etc --copy-up=/run --propagation=rslave /usr/bin/dockerd-rootless.sh jean 519119 519087 1 17:03 ? 00:00:18 dockerd jean 519146 519119 0 17:03 ? 00:00:01 containerd --config /run/user/1000/docker/containerd/containerd.toml jean 549474 389712 0 17:24 pts/0 00:00:00 grep --color=auto -i docker


**Expected behavior**
The manual build is not working with the newer releases of `goreleases` along with not following the changes that happened over the time. 
It seems that might work on a very specific condition, which is not what's expected. But if so, it should be detailed in the documentation to avoid such problems.

**Environment**

$ cat /etc/*-release Fedora release 39 (Thirty Nine) NAME="Fedora Linux" VERSION="39 (Workstation Edition)"

$ uname -r 6.10.3-100.fc39.x86_64

$ docker version Client: Docker Engine - Community Version: 27.1.1 API version: 1.46 Go version: go1.21.12 Git commit: 6312585 Built: Tue Jul 23 19:59:02 2024 OS/Arch: linux/amd64 Context: default

Server: Docker Engine - Community Engine: Version: 27.1.1 API version: 1.46 (minimum version 1.24) Go version: go1.21.12 Git commit: cc13f95 Built: Tue Jul 23 19:57:16 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.19 GitCommit: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41 runc: Version: 1.7.19 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0 rootlesskit: Version: 2.0.2 ApiVersion: 1.1.1 NetworkDriver: slirp4netns PortDriver: builtin StateDir: /run/user/1000/dockerd-rootless slirp4netns: Version: 1.2.2 GitCommit: 0ee2d87523e906518d34a6b423271e4826f71faf


Also tested with Ubuntu 24.04 and arm64 Darwin Kernel Version 23.6.0; All with the same scenarios
BupycHuk commented 2 weeks ago

Hi @jenunes, I've updated goreleaser and fixed Makefile. Please check it https://github.com/percona/mongodb_exporter/pull/931