Skip to content

Commit

Permalink
Merge pull request #15 from Intellection/upgrades
Browse files Browse the repository at this point in the history
Fixes & upgrades
  • Loading branch information
zacblazic authored Mar 8, 2023
2 parents ae02ae5 + 62267ba commit 6ba0134
Show file tree
Hide file tree
Showing 487 changed files with 638 additions and 363,513 deletions.
7 changes: 4 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*

!.git
!.promu.yml
!passenger_exporter.go
!passenger_exporter_test.go
!go.mod
!go.sum
!main.go
!Makefile
!vendor/
!VERSION
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: tests

on:
pull_request:
branches:
- master
push:
branches:
- master

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
cache: true
- name: Run Linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
cache: true
- name: Build
run: go build -v ./...
- name: Run Tests
run: go test -json ./... > test-results.json
- name: Annotate Tests
if: always()
uses: guyarb/[email protected]
with:
test-results: test-results.json
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
passenger-exporter

bin/
vendor/
18 changes: 7 additions & 11 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
go:
version: 1.9.4
version: 1.20.1
repository:
path: github.com/Intellection/passenger-exporter
build:
binaries:
- name: passenger-exporter
flags: -a -tags -installsuffix
flags: -a -tags -netgo
ldflags: |
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug exporter",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"env": { "PASSENGER_INSTANCE_REGISTRY_DIR": "/tmp/passenger"}
}
]
}
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## 1.0.0

### Breaking Changes
* Rename `app_count` metric to `app_group_count`.
* Update `proc_start_time_seconds` metric to correctly be in unix seconds.
* Update default value for `-passenger.command.timeout-seconds` flag to `5s`.
* Remove process metrics collector.
* Remomve `/` endpoint showing link to metrics path.

### Bug Fixes
* Prevent index out of range panics when the number of passenger processes surges past the max pool size temporarily when replacing an existing process.

### Improvements
* Upgrade to Go `v1.20.1`.
* Switch Go modules.
* Upgrade Go dependencies.
* Upgrade bundled Passenger to `v6.0.17`.
* Switch container image from Alpine Linux to Debian Bullseye.
* Use builder pattern to build binary and copy it into runner image.
* Run container as `exporter` user instead of `nobody`.
* Add new fields parsed from passenger status command.
* Use expected types in structs instead of parsing afterwards.
* Configure `promu` to use `netgo` instead of `installsuffix`.
* Switch to `sirupsen/logrus` logger as `prometheus/common` no longer includes it.
* Add launch configuration for debugging in Visual Studio Code.
* Add GitHub Actions workflow for testing and linting.
* Simplify Makefile for single command builds.

## 0.7.1

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @Intellection/devops
* @Intellection/sre
85 changes: 43 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
FROM ruby:2.4.3-alpine3.7
ARG GOLANG_VERSION="1.20.1"
ARG DEBIAN_VERSION="bullseye-20230227-slim"

ARG GOLANG_VERSION="1.9.4-r0"
ARG BUILD_DEPS="go=$GOLANG_VERSION ruby-dev linux-headers curl curl-dev pcre-dev libexecinfo-dev@edge-main"
ARG RUNTIME_DEPS="tini build-base pcre git libexecinfo@edge-main"
ARG BUILDER_IMAGE="golang:${GOLANG_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

RUN echo '@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main/' >> /etc/apk/repositories && \
apk update && \
apk upgrade && \
apk add $BUILD_DEPS && \
apk add $RUNTIME_DEPS && \
mkdir -p /opt
FROM ${BUILDER_IMAGE} AS builder

# Passenger
ENV PASSENGER_VERSION="5.1.12" \
PATH="/opt/passenger/bin:$PATH"
RUN curl -L "https://s3.amazonaws.com/phusion-passenger/releases/passenger-$PASSENGER_VERSION.tar.gz" | tar -xzf - -C /opt && \
mv /opt/passenger-$PASSENGER_VERSION /opt/passenger && \
passenger-config validate-install --auto && \
export EXTRA_PRE_CFLAGS='-O' EXTRA_PRE_CXXFLAGS='-O' EXTRA_LDFLAGS='-lexecinfo' && \
passenger-config compile-agent --optimize && \
passenger-config install-standalone-runtime && \
passenger-config build-native-support
WORKDIR /opt/app

# Install build tools
RUN go install github.com/prometheus/[email protected]

# Add source files and build
ADD . ./
RUN make

# Go configuration
ENV GOROOT="/usr/lib/go" \
GOPATH="/go"
ENV PATH="$GOPATH/bin:$GOROOT/bin:$PATH"
FROM ${RUNNER_IMAGE}

# Go dependencies
RUN go get github.com/prometheus/promu
RUN apt-get update -y && \
apt-get install -y \
bash \
ca-certificates \
gnupg && \
apt clean && \
rm -rf /var/lib/apt/lists/*

# Configure source path
ARG SOURCE_PATH="/go/src/github.com/Intellection/passenger-exporter"
RUN mkdir -p ${SOURCE_PATH}
ARG APP_USER="exporter"
ENV APP_HOME="/opt/app"

# Add source files
ADD . ${SOURCE_PATH}/
WORKDIR ${SOURCE_PATH}
WORKDIR ${APP_HOME}

# Build exporter
RUN promu build && \
mv ${SOURCE_PATH}/passenger-exporter /usr/local/bin/passenger-exporter && \
rm -rf ${SOURCE_PATH}/*
# Create user
RUN groupadd -g 9999 ${APP_USER} && \
useradd --system --create-home -u 9999 -g 9999 ${APP_USER}

# Passenger
ARG PASSENGER_VERSION="6.0.17"
ARG PASSENGER_PKG="1:${PASSENGER_VERSION}-1~bullseye1"
RUN apt-key adv --no-tty --keyserver hkps://keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 && \
echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger bullseye main' > /etc/apt/sources.list.d/passenger.list && \
apt-get update -y && \
apt-get install -y passenger=${PASSENGER_PKG} && \
passenger-config validate-install --auto && \
apt clean && \
rm -rf /var/lib/apt/lists/*

# Cleanup
RUN apk del $BUILD_PACKAGES && \
rm -rf /var/cache/apk/*
# Copy files from builder
COPY --from=builder --chown=${APP_USER}:${APP_USER} ${APP_HOME}/bin/ ./bin/

USER nobody:nobody
# Run as user
USER ${APP_USER}:${APP_USER}

ENTRYPOINT ["tini", "--", "passenger-exporter"]
CMD ["/bin/sh"]
ENTRYPOINT ["./bin/passenger-exporter"]
37 changes: 18 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
VERSION := $(shell cat VERSION)
BIN := passenger-exporter
CONTAINER := passenger-exporter
GOOS ?= linux
GOARCH ?= amd64
BIN_DIR := ./bin

GOFLAGS := -ldflags "-X main.Version=$(VERSION)" -a -installsuffix cgo
TAR := $(BIN)-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz
DST ?= http://ent.int.s-cloud.net/iss/$(BIN)
.PHONY: all
all: dependencies build

PREFIX ?= $(shell pwd)
.PHONY: build
build:
promu build --prefix=$(BIN_DIR)

default: $(BIN)
.PHONY: test
test:
go test -v ./...

$(BIN):
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) promu build --prefix $(PREFIX)
.PHONY: lint
lint:
golangci-lint run

release: $(TAR)
curl -XPOST --data-binary @$< $(DST)/$<
.PHONY: dependencies
dependencies:
go mod vendor

build-docker: $(BIN)
docker build -t $(CONTAINER) .

$(TAR): $(BIN)
tar czf $@ $<
.PHONY: clean
clean:
rm -rf ${BIN_DIR}
80 changes: 50 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
# Passenger Exporter

Prometheus exporter for [Phusion Passenger](https://www.phusionpassenger.com) metrics.
Passenger exporter is a [Prometheus] metrics exporter for [Phusion Passenger] 6.0.

## Flags
## Usage

### Running locally
Start Passenger with a known [instance registry]:
```console
$ PASSENGER_INSTANCE_REGISTRY_DIR=/tmp/passenger passenger start
```
-log.format value
If set use a syslog logger or JSON logging.
Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true.
Defaults to stderr.
-log.level value
Only log messages with the given severity or above.
Valid levels: [debug, info, warn, error, fatal]. (default info)
-passenger.command string
Passenger command for querying passenger status.
(default "passenger-status --show=xml")
-passenger.pid-file string
Optional path to a file containing the passenger PID for additional metrics.
-passenger.command.timeout-seconds float
Timeout for passenger.command. (default 0.5 seconds)
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9149")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")

Run the exporter, specifying the same [instance registry]:
```console
$ PASSENGER_INSTANCE_REGISTRY_DIR=/tmp/passenger ./bin/passenger-exporter
```

**Note**: You must specify the [`PASSENGER_INSTANCE_REGISTRY_DIR`] environment variable. It is used by the [`passenger-status`] command to query Passenger information. Without it, the exporter cannot retreve metrics from your Passenger instance.

## Running Tests
### Flags

Tests can be run with:
```
go test .
```
The following flags are available:

Additionally, the test/scrape_output.txt can be regenerated by passing the
`--golden` flag:
```
go test -v . --golden
```
| Flag | Description | Default Value |
|-----------------------------------------|--------------------------------------------------------|----------------------------|
| `-passenger.command string` | Passenger command for querying passenger status. | `"passenger-status --show=xml"` |
| `-passenger.command.timeout-seconds float` | Timeout for passenger.command. | `5` |
| `-web.listen-address string` | Address to listen on for web interface and telemetry. | `":9149"` |
| `-web.telemetry-path string` | Path under which to expose metrics. | `"/metrics"` |


## Building

1. Clone the repository.
2. Install the [`promu`] build tool.
2. Install application dependencies via `make dependencies` (they'll be placed in `./vendor`).
3. Build and install the binary with `make build`.
4. Run the command e.g. `./bin/passenger-exporter -h`.

## Testing

1. Install the `golangci-lint`, [see instructions here][golangci-lint-install].
2. Run linter using `make lint` and test using `make test`.

The scrape output can be regenerated by passing the `--golden` flag to `go test`.

## Credits

We would like to acknowledge and express our gratitude to [@stuartnelson3] for their work on the [upstream version of Passenger Exporter].

[`PASSENGER_INSTANCE_REGISTRY_DIR`]: https://www.phusionpassenger.com/library/config/standalone/reference/#--instance-registry-dir-instance_registry_dir
[`passenger-status`]: https://www.phusionpassenger.com/library/admin/standalone/overall_status_report.html
[`promu`]: github.com/prometheus/promu
[golang-quickstart]: https://go.dev/doc/tutorial/getting-started
[golangci-lint-install]: https://golangci-lint.run/usage/install/
[Phusion Passenger]: https://www.phusionpassenger.com/
[Prometheus]: https://prometheus.io/
[instance registry]: https://www.phusionpassenger.com/library/config/standalone/reference/#--instance-registry-dir-instance_registry_dir
[upstream version of Passenger Exporter]: https://github.com/stuartnelson3/passenger_exporter
[@stuartnelson3]: https://github.com/stuartnelson3/
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.1
1.0.0
Loading

0 comments on commit 6ba0134

Please sign in to comment.