chore: add e2e tests
This commit is contained in:
parent
9009bcf341
commit
e9a9eda972
6 changed files with 156 additions and 19 deletions
4
Makefile
4
Makefile
|
@ -19,9 +19,11 @@ test-coverage-html: ## Create a code coverage report in HTML
|
|||
go test -coverprofile .cover/cover.out ./...
|
||||
go tool cover -html .cover/cover.out
|
||||
|
||||
test-e2e:
|
||||
bats tests/e2e.bats
|
||||
|
||||
lint: ## Run linters
|
||||
golangci-lint run
|
||||
|
||||
fmt: ## Fix formatting issues
|
||||
goimports -w .
|
||||
|
||||
|
|
70
README.md
70
README.md
|
@ -1,10 +1,9 @@
|
|||
# php-fpm_exporter
|
||||
|
||||
[![CircleCI](https://circleci.com/gh/hipages/php-fpm_exporter.svg?style=shield)](https://circleci.com/gh/hipages/php-fpm_exporter)
|
||||
![Test](https://github.com/hipages/php-fpm_exporter/workflows/Test/badge.svg)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/hipages/php-fpm_exporter)](https://goreportcard.com/report/github.com/hipages/php-fpm_exporter)
|
||||
[![GoDoc](https://godoc.org/github.com/hipages/php-fpm_exporter?status.svg)](https://godoc.org/github.com/hipages/php-fpm_exporter)
|
||||
[![Maintainability](https://api.codeclimate.com/v1/badges/52f9e1f0388e8aa38bfe/maintainability)](https://codeclimate.com/github/hipages/php-fpm_exporter/maintainability)
|
||||
[![Test Coverage](https://api.codeclimate.com/v1/badges/52f9e1f0388e8aa38bfe/test_coverage)](https://codeclimate.com/github/hipages/php-fpm_exporter/test_coverage)
|
||||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=hipages_php-fpm_exporter&metric=alert_status)](https://sonarcloud.io/dashboard?id=hipages_php-fpm_exporter)
|
||||
[![Docker Pulls](https://img.shields.io/docker/pulls/hipages/php-fpm_exporter.svg)](https://hub.docker.com/r/hipages/php-fpm_exporter/)
|
||||
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/hipages/php-fpm_exporter.svg)](http://isitmaintained.com/project/hipages/php-fpm_exporter "Average time to resolve an issue")
|
||||
[![Percentage of issues still open](http://isitmaintained.com/badge/open/hipages/php-fpm_exporter.svg)](http://isitmaintained.com/project/hipages/php-fpm_exporter "Percentage of issues still open")
|
||||
|
@ -16,6 +15,28 @@ The exporter connects directly to PHP-FPM and exports the metrics via HTTP.
|
|||
|
||||
A webserver such as NGINX or Apache is **NOT** needed!
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
* [Options and defaults](#options-and-defaults)
|
||||
* [Why `--phpfpm.fix-process-count`?](#why---phpfpmfix-process-count)
|
||||
* [CLI Examples](#cli-examples)
|
||||
* [Docker Examples](#docker-examples)
|
||||
* [Kubernetes Example](#kubernetes-example)
|
||||
- [Metrics collected](#metrics-collected)
|
||||
- [Grafana Dasbhoard for Kubernetes](#grafana-dasbhoard-for-kubernetes)
|
||||
- [FAQ](#faq)
|
||||
- [Development](#development)
|
||||
* [E2E Tests](#e2e-tests)
|
||||
- [Contributing](#contributing)
|
||||
- [Contributors](#contributors)
|
||||
- [Alternatives](#alternatives)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Features
|
||||
|
||||
* Export single or multiple pools
|
||||
|
@ -106,6 +127,8 @@ If you like to have a more granular reporting please use `phpfpm_process_state`.
|
|||
|
||||
### Kubernetes Example
|
||||
|
||||
TBD
|
||||
|
||||
## Metrics collected
|
||||
|
||||
```
|
||||
|
@ -153,14 +176,6 @@ The Grafana dashboard can be found [here](https://grafana.com/dashboards/4912).
|
|||
|
||||
<img src="https://grafana.com/api/dashboards/4912/images/3079/image" width="600">
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are greatly appreciated.
|
||||
The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers.
|
||||
The project follows the typical GitHub pull request model.
|
||||
See " [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) " for more details.
|
||||
Before starting any work, please either comment on an existing issue, or file a new one.
|
||||
|
||||
## FAQ
|
||||
|
||||
* **How to update "Metrics collected"?**
|
||||
|
@ -170,11 +185,30 @@ Before starting any work, please either comment on an existing issue, or file a
|
|||
curl http://127.0.0.1:12345/metrics | grep phpfpm | grep "#"
|
||||
```
|
||||
|
||||
## Alternatives
|
||||
## Development
|
||||
|
||||
* [bakins/php-fpm-exporter](https://github.com/bakins/php-fpm-exporter)
|
||||
* [peakgames/php-fpm-prometheus](https://github.com/peakgames/php-fpm-prometheus)
|
||||
* [craigmj/phpfpm_exporter](https://github.com/craigmj/phpfpm_exporter)
|
||||
### E2E Tests
|
||||
|
||||
The E2E tests are based on docker-compose and bats-core. Install the required components, e.g. via brew on MacOS:
|
||||
|
||||
```bash
|
||||
brew tap kaos/shell
|
||||
brew install docker-compose bats-core kaos/shell/bats-assert kaos/shell/bats-support
|
||||
```
|
||||
|
||||
After the components are installed run the E2E tests:
|
||||
|
||||
```bash
|
||||
make tests-e2e
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are greatly appreciated.
|
||||
The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers.
|
||||
The project follows the typical GitHub pull request model.
|
||||
See " [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) " for more details.
|
||||
Before starting any work, please either comment on an existing issue, or file a new one.
|
||||
|
||||
## Contributors
|
||||
|
||||
|
@ -198,3 +232,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
|
|||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
|
||||
## Alternatives
|
||||
|
||||
* [bakins/php-fpm-exporter](https://github.com/bakins/php-fpm-exporter)
|
||||
* [peakgames/php-fpm-prometheus](https://github.com/peakgames/php-fpm-prometheus)
|
||||
* [craigmj/phpfpm_exporter](https://github.com/craigmj/phpfpm_exporter)
|
||||
|
|
32
test/docker-compose-e2e.yml
Normal file
32
test/docker-compose-e2e.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
phpfpm1:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9031:9000"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
phpfpm2:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9032:9000"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
phpfpm3:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9033:9000"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
exporter:
|
||||
image: hipages/php-fpm_exporter:latest
|
||||
ports:
|
||||
- "9253:9253"
|
||||
environment:
|
||||
PHP_FPM_SCRAPE_URI: "tcp://phpfpm1:9000/status,tcp://phpfpm2:9000/status,tcp://phpfpm3:9000/status"
|
||||
PHP_FPM_LOG_LEVEL: "debug"
|
31
test/docker-compose-local.yml
Normal file
31
test/docker-compose-local.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
prometheus:
|
||||
image: quay.io/prometheus/prometheus:latest
|
||||
ports:
|
||||
- 9090:9090
|
||||
volumes:
|
||||
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
|
||||
|
||||
phpfpm:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9000:9000"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
phpfpm1:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9001:9001"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
phpfpm2:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9002:9002"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
|
@ -11,13 +11,11 @@ services:
|
|||
|
||||
phpfpm:
|
||||
image: hipages/php
|
||||
ports:
|
||||
- "9000:9000"
|
||||
environment:
|
||||
PHP_FPM_PM_STATUS_PATH: "/status"
|
||||
|
||||
exporter:
|
||||
image: hipages/php-fpm_exporter:0.0.4
|
||||
image: hipages/php-fpm_exporter:latest
|
||||
ports:
|
||||
- "9253:9253"
|
||||
environment:
|
||||
|
|
34
test/e2e.bats
Normal file
34
test/e2e.bats
Normal file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load '/usr/local/lib/bats-support/load.bash'
|
||||
load '/usr/local/lib/bats-assert/load.bash'
|
||||
|
||||
setup () {
|
||||
docker-compose -f ./test/docker-compose-e2e.yml up -d
|
||||
# Workaround to wait for docker to start containers
|
||||
sleep 5
|
||||
#go run main.go server --phpfpm.scrape-uri tcp://127.0.0.1:9031/status,tcp://127.0.0.1:9032/status 3>&- &
|
||||
}
|
||||
|
||||
teardown() {
|
||||
docker-compose -f ./test/docker-compose-e2e.yml stop
|
||||
docker-compose -f ./test/docker-compose-e2e.yml rm -f
|
||||
docker-compose -f ./test/docker-compose-e2e.yml down --volumes
|
||||
}
|
||||
|
||||
@test "Should have metrics endpoint" {
|
||||
run curl -sSL http://localhost:9253/metrics
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "Should have metric phpfpm_up" {
|
||||
run curl -sSL http://localhost:9253/metrics
|
||||
assert_output --partial '# TYPE phpfpm_up gauge'
|
||||
}
|
||||
|
||||
@test "Should have scraped multiple PHP-FPM pools" {
|
||||
run curl -sSL http://localhost:9253/metrics
|
||||
assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm1:9000/status"} 1'
|
||||
assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm2:9000/status"} 1'
|
||||
assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm3:9000/status"} 1'
|
||||
}
|
Loading…
Reference in a new issue