diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..d868d90 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,168 @@ +--- +version: 2 + +jobs: + test: + docker: + - image: circleci/golang:1.10 + working_directory: /go/src/github.com/prometheus/mysqld_exporter + + steps: + - checkout + - run: make promu + - run: make + - run: rm -v mysqld_exporter + + codespell: + docker: + - image: circleci/python + + steps: + - checkout + - run: sudo pip install codespell + - run: codespell --skip=".git,./vendor,ttar" + + build: + machine: true + working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/mysqld_exporter + + environment: + DOCKER_IMAGE_NAME: prom/mysqld-exporter + QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter + DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base + REPO_PATH: github.com/prometheus/mysqld_exporter + + steps: + - checkout + - run: make promu + - run: promu crossbuild -v + - persist_to_workspace: + root: . + paths: + - .build + - run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter + - run: + command: | + if [ -n "$CIRCLE_TAG" ]; then + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + else + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME + make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME + fi + - run: docker images + - run: docker network create mysql-test + - run: docker run --network mysql-test -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 -d percona/percona-server:latest + + - run: docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T + - run: + command: | + if [ -n "$CIRCLE_TAG" ]; then + make test-docker DOCKER_IMAGE_TAG=$CIRCLE_TAG + else + make test-docker + fi + + docker_hub_master: + docker: + - image: circleci/golang:1.10 + working_directory: /go/src/github.com/prometheus/mysqld_exporter + + environment: + DOCKER_IMAGE_NAME: prom/mysqld-exporter + QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter + DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base + REPO_PATH: github.com/prometheus/mysqld_exporter + + steps: + - checkout + - setup_remote_docker + - attach_workspace: + at: . + - run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter + - run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME + - run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME + - run: docker images + - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io + - run: docker push $DOCKER_IMAGE_NAME + - run: docker push $QUAY_IMAGE_NAME + + docker_hub_release_tags: + docker: + - image: circleci/golang:1.10 + working_directory: /go/src/github.com/prometheus/mysqld_exporter + + environment: + DOCKER_IMAGE_NAME: prom/mysqld-exporter + QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter + DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base + REPO_PATH: github.com/prometheus/mysqld_exporter + + steps: + - checkout + - setup_remote_docker + - run: mkdir -v -p ${HOME}/bin + - run: curl -L 'https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C ${HOME}/bin + - run: echo 'export PATH=${HOME}/bin:${PATH}' >> ${BASH_ENV} + - attach_workspace: + at: . + - run: make promu + - run: promu crossbuild tarballs + - run: promu checksum .tarballs + - run: promu release .tarballs + - store_artifacts: + path: .tarballs + destination: releases + - run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter + - run: + command: | + if [ -n "$CIRCLE_TAG" ]; then + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + else + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME + make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME + fi + - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io + - run: | + if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then + docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" + docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" + fi + - run: docker push $DOCKER_IMAGE_NAME:$CIRCLE_TAG + - run: docker push $QUAY_IMAGE_NAME:$CIRCLE_TAG + +workflows: + version: 2 + mysqld_exporter: + jobs: + - test: + filters: + tags: + only: /.*/ + - build: + filters: + tags: + only: /.*/ + - codespell: + filters: + tags: + only: /.*/ + - docker_hub_master: + requires: + - test + - build + filters: + branches: + only: master + - docker_hub_release_tags: + requires: + - test + - build + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ diff --git a/.travis.yml b/.travis.yml index c2ab3f9..8e29986 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,8 @@ sudo: required language: go go: -- 1.8.x - 1.9.x -- master +- 1.10.x env: - MYSQL_IMAGE=mysql/mysql-server:5.5 diff --git a/Makefile b/Makefile index 268af1e..276c3cd 100644 --- a/Makefile +++ b/Makefile @@ -11,55 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -GO := go -FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) -PROMU := $(FIRST_GOPATH)/bin/promu -pkgs = $(shell $(GO) list ./... | grep -v /vendor/) +all: vet -PREFIX ?= $(shell pwd) -BIN_DIR ?= $(shell pwd) -DOCKER_IMAGE_NAME ?= mysqld-exporter -DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) +include Makefile.common +STATICCHECK_IGNORE = \ + github.com/prometheus/mysqld_exporter/mysqld_exporter.go:SA1019 -all: format build test-short +DOCKER_IMAGE_NAME ?= mysqld-exporter -style: - @echo ">> checking code style" - @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' +test-docker: + @echo ">> testing docker image" + ./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9104 -test-short: - @echo ">> running short tests" - @$(GO) test -short -race $(pkgs) - -test: - @echo ">> running tests" - @$(GO) test -race $(pkgs) - -format: - @echo ">> formatting code" - @$(GO) fmt $(pkgs) - -vet: - @echo ">> vetting code" - @$(GO) vet $(pkgs) - -build: promu - @echo ">> building binaries" - @$(PROMU) build --prefix $(PREFIX) - -tarball: promu - @echo ">> building release tarball" - @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) - -docker: - @echo ">> building docker image" - @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . - -promu: - @GOOS=$(shell uname -s | tr A-Z a-z) \ - GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ - $(GO) get -u github.com/prometheus/promu - - -.PHONY: all style format build test vet tarball docker promu +.PHONY: test-docker diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..353494c --- /dev/null +++ b/Makefile.common @@ -0,0 +1,100 @@ +# Copyright 2018 The Prometheus Authors +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# A common Makefile that includes rules to be reused in different prometheus projects. +# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository! + +# Example usage : +# Create the main Makefile in the root project directory. +# include Makefile.common +# customTarget: +# @echo ">> Running customTarget" +# + +# Ensure GOBIN is not set during build so that promu is installed to the correct path +unexport GOBIN + +GO ?= go +GOFMT ?= $(GO)fmt +FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) +PROMU := $(FIRST_GOPATH)/bin/promu +STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck +GOVENDOR := $(FIRST_GOPATH)/bin/govendor +pkgs = ./... + +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) + +all: style staticcheck unused build test + +style: + @echo ">> checking code style" + ! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +check_license: + @echo ">> checking license header" + @licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \ + awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \ + done); \ + if [ -n "$${licRes}" ]; then \ + echo "license header checking failed:"; echo "$${licRes}"; \ + exit 1; \ + fi + +test-short: + @echo ">> running short tests" + $(GO) test -short $(pkgs) + +test: + @echo ">> running all tests" + $(GO) test -race $(pkgs) + +format: + @echo ">> formatting code" + $(GO) fmt $(pkgs) + +vet: + @echo ">> vetting code" + $(GO) vet $(pkgs) + +staticcheck: $(STATICCHECK) + @echo ">> running staticcheck" + $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) + +unused: $(GOVENDOR) + @echo ">> running check for unused packages" + @$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages' + +build: promu + @echo ">> building binaries" + $(PROMU) build --prefix $(PREFIX) + +tarball: promu + @echo ">> building release tarball" + $(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) + +docker: + docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + +promu: + GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu + +$(FIRST_GOPATH)/bin/staticcheck: + GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck + +$(FIRST_GOPATH)/bin/govendor: + GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor + +.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor \ No newline at end of file diff --git a/README.md b/README.md index ee48b8d..c0dddda 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ NOTE: It is recommended to set a max connection limit for the user to avoid over Running using an environment variable: - export DATA_SOURCE_NAME='login:password@(hostname:port)/' + export DATA_SOURCE_NAME='user:password@(hostname:3306)/' ./mysqld_exporter Running using ~/.my.cnf: @@ -106,10 +106,14 @@ You can deploy this exporter using the [prom/mysqld-exporter](https://registry.h For example: ```bash +docker network create my-mysql-network docker pull prom/mysqld-exporter -docker run -d -p 9104:9104 --link=my_mysql_container:bdd \ - -e DATA_SOURCE_NAME="user:password@(bdd:3306)/database" prom/mysqld-exporter +docker run -d \ + -p 9104:9104 \ + --network my-mysql-network \ + -e DATA_SOURCE_NAME="user:password@(my-mysql-network:3306)/" \ + prom/mysqld-exporter ``` ## heartbeat diff --git a/circle.yml b/circle.yml deleted file mode 100644 index a90a9a2..0000000 --- a/circle.yml +++ /dev/null @@ -1,62 +0,0 @@ -machine: - environment: - DOCKER_IMAGE_NAME: prom/mysqld-exporter - QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter - DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.8-base - REPO_PATH: github.com/prometheus/mysqld_exporter - pre: - - sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci' - - sudo chmod 0755 /usr/bin/docker - - sudo curl -L 'https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C $HOME/bin - services: - - docker - -dependencies: - pre: - - make promu - - docker info - override: - - promu crossbuild - - ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter - - | - if [ -n "$CIRCLE_TAG" ]; then - make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG - make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG - else - make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME - make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME - fi - post: - - mkdir $CIRCLE_ARTIFACTS/binaries/ && cp -a .build/* $CIRCLE_ARTIFACTS/binaries/ - - docker images - -test: - override: - - docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T - -deployment: - hub_branch: - branch: master - owner: prometheus - commands: - - docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - - docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - - docker push $DOCKER_IMAGE_NAME - - docker push $QUAY_IMAGE_NAME - hub_tag: - tag: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ - owner: prometheus - commands: - - promu crossbuild tarballs - - promu checksum .tarballs - - promu release .tarballs - - mkdir $CIRCLE_ARTIFACTS/releases/ && cp -a .tarballs/* $CIRCLE_ARTIFACTS/releases/ - - docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - - docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - - | - if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then - docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" - docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" - fi - - docker push $DOCKER_IMAGE_NAME - - docker push $QUAY_IMAGE_NAME diff --git a/collector/binlog_test.go b/collector/binlog_test.go index 408c552..0c02a9a 100644 --- a/collector/binlog_test.go +++ b/collector/binlog_test.go @@ -47,6 +47,6 @@ func TestScrapeBinlogSize(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/engine_innodb_test.go b/collector/engine_innodb_test.go index d3cf5c5..fef0132 100644 --- a/collector/engine_innodb_test.go +++ b/collector/engine_innodb_test.go @@ -160,6 +160,6 @@ END OF INNODB MONITOR OUTPUT // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/engine_tokudb_test.go b/collector/engine_tokudb_test.go index 158bf8c..89d28a8 100644 --- a/collector/engine_tokudb_test.go +++ b/collector/engine_tokudb_test.go @@ -64,6 +64,6 @@ func TestScrapeEngineTokudbStatus(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/global_status.go b/collector/global_status.go index df625f8..a7cfc58 100644 --- a/collector/global_status.go +++ b/collector/global_status.go @@ -13,7 +13,7 @@ import ( const ( // Scrape query globalStatusQuery = `SHOW GLOBAL STATUS` - // Subsytem. + // Subsystem. globalStatus = "global_status" ) diff --git a/collector/global_status_test.go b/collector/global_status_test.go index 01e3fe5..536b54b 100644 --- a/collector/global_status_test.go +++ b/collector/global_status_test.go @@ -68,6 +68,6 @@ func TestScrapeGlobalStatus(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/global_variables_test.go b/collector/global_variables_test.go index 5ad7e11..319569a 100644 --- a/collector/global_variables_test.go +++ b/collector/global_variables_test.go @@ -64,7 +64,7 @@ func TestScrapeGlobalVariables(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/heartbeat_test.go b/collector/heartbeat_test.go index 1cbe949..0fb52d1 100644 --- a/collector/heartbeat_test.go +++ b/collector/heartbeat_test.go @@ -44,6 +44,6 @@ func TestScrapeHeartbeat(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_clientstats_test.go b/collector/info_schema_clientstats_test.go index 911f1b7..96dc4fe 100644 --- a/collector/info_schema_clientstats_test.go +++ b/collector/info_schema_clientstats_test.go @@ -65,6 +65,6 @@ func TestScrapeClientStat(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_innodb_metrics_test.go b/collector/info_schema_innodb_metrics_test.go index 7d549df..aa04259 100644 --- a/collector/info_schema_innodb_metrics_test.go +++ b/collector/info_schema_innodb_metrics_test.go @@ -64,6 +64,6 @@ func TestScrapeInnodbMetrics(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_innodb_sys_tablespaces_test.go b/collector/info_schema_innodb_sys_tablespaces_test.go index 162fd26..1812e9e 100644 --- a/collector/info_schema_innodb_sys_tablespaces_test.go +++ b/collector/info_schema_innodb_sys_tablespaces_test.go @@ -47,6 +47,6 @@ func TestScrapeInfoSchemaInnodbTablespaces(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_query_response_time_test.go b/collector/info_schema_query_response_time_test.go index 5e934e1..bfb1e7c 100644 --- a/collector/info_schema_query_response_time_test.go +++ b/collector/info_schema_query_response_time_test.go @@ -73,6 +73,6 @@ func TestScrapeQueryResponseTime(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_tablestats_test.go b/collector/info_schema_tablestats_test.go index f690b0a..e56a48b 100644 --- a/collector/info_schema_tablestats_test.go +++ b/collector/info_schema_tablestats_test.go @@ -53,6 +53,6 @@ func TestScrapeTableStat(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/info_schema_userstats_test.go b/collector/info_schema_userstats_test.go index d988616..4bbb6ef 100644 --- a/collector/info_schema_userstats_test.go +++ b/collector/info_schema_userstats_test.go @@ -65,6 +65,6 @@ func TestScrapeUserStat(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/perf_schema_file_instances_test.go b/collector/perf_schema_file_instances_test.go index 932fdb7..06cd95a 100644 --- a/collector/perf_schema_file_instances_test.go +++ b/collector/perf_schema_file_instances_test.go @@ -62,6 +62,6 @@ func TestScrapePerfFileInstances(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/perf_schema_index_io_waits_test.go b/collector/perf_schema_index_io_waits_test.go index 3ece0a7..393c43c 100644 --- a/collector/perf_schema_index_io_waits_test.go +++ b/collector/perf_schema_index_io_waits_test.go @@ -56,6 +56,6 @@ func TestScrapePerfIndexIOWaits(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/collector/slave_status_test.go b/collector/slave_status_test.go index 0ede112..3052eed 100644 --- a/collector/slave_status_test.go +++ b/collector/slave_status_test.go @@ -44,6 +44,6 @@ func TestScrapeSlaveStatus(t *testing.T) { // Ensure all SQL queries were executed if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expections: %s", err) + t.Errorf("there were unfulfilled exceptions: %s", err) } } diff --git a/test_image.sh b/test_image.sh new file mode 100755 index 0000000..c3cfe27 --- /dev/null +++ b/test_image.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -exo pipefail + +docker_image=$1 +port=$2 + +container_id='' + +wait_start() { + for in in {1..10}; do + if /usr/bin/curl -s -m 5 -f "http://localhost:${port}/metrics" > /dev/null; then + docker_cleanup + exit 0 + else + sleep 1 + fi + done + + exit 1 +} + +docker_start() { + container_id=$(docker run -d --network mysql-test -e DATA_SOURCE_NAME="root:secret@(mysql-test:3306)/" -p "${port}":"${port}" "${docker_image}") +} + +docker_cleanup() { + docker kill "${container_id}" +} + +if [[ "$#" -ne 2 ]] ; then + echo "Usage: $0 quay.io/prometheus/mysqld-exporter:v0.10.0 9104" >&2 + exit 1 +fi + +docker_start +wait_start