Skip to content

Commit e3ba4b3

Browse files
authored
Merge pull request prometheus-community#33 from wrouesnel/bugfixes_and_upgrades
Bugfixes and upgrades
2 parents 9143f59 + 98d26cb commit e3ba4b3

File tree

219 files changed

+117577
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+117577
-288
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.build
22
postgres_exporter
3+
postgres_exporter_integration_test
34
*.tar.gz
45
*.test
56
*-stamp

.travis.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@ services:
44
language: go
55
go:
66
- '1.7'
7+
# Make sure we have p2 and the postgres client.
8+
before_install:
9+
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
10+
sudo chmod +x /usr/local/bin/p2
11+
- sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
12+
sudo chmod +x /usr/local/bin/docker-compose
13+
- sudo apt-get update && sudo apt-get install postgresql-client-common
14+
715
script:
816
- make all
917
- make docker
1018
- make test-integration
1119
after_success:
12-
- if [ "$TRAVIS_BRANCH" == "master" ]; then docker login -e $DOCKER_EMAIL -u $DOCKER_USER
13-
-p $DOCKER_PASS ; docker push wrouesnel/postgres_exporter ; fi
20+
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
21+
# Push a tagged build if a tag is found.
22+
- if [ ! -z "$TRAVIS_TAG" ]; then
23+
docker tag wrouesnel/postgres_exporter:latest wrouesnel/postgres_exporter:$TRAVIS_TAG ;
24+
fi
25+
# Push a latest version
26+
- if [ "$TRAVIS_BRANCH" == "master" ]; then docker push wrouesnel/postgres_exporter ; fi
1427
env:
1528
global:
1629
- secure: RfoWQj5tEB/t3XL2tqJW7u7Qscpz1QBOfF9lMFpB4kAUMTtZU0zBbXfMo1JheGoJQQxD/7NLRHhbUWPT2489o3KKpRTQ7RHn3k8n5U7opH01bWX0+l/EPVmhlsKjSDSLGgmxz80j3I6C8ZV3qDUijSx7r90QUNHGbZtV7g+KtoUTpRV0zir/heK6qq9LHWNHbNsJyHK8qHmd6g1UzWIBaZPJ6a/n/rO2jq4uS1JR0VlIJPRF11HOLH8IjFQvVYpN7YbEslxyNsfQJUSP/7CghSLLVWPSATEjMm8a5GJVLc564+nYghm484psEtiMXkZ3n6ie7AT8aJrKfexWrwh2aCc+cK4PiyXrf4euZehZNYogmFCqWzd1LJKcN2uIkpBSuZQDm3e6c4qkkWGpx+RdFWtAMG8IgZLDbcuryxFNzMwHc2CJ009s9Zsa+g7D57csyR5LCZ8YtNGI3g8FmhwpCKvYkfKa9aijUEWyJMyT4Vhd/w7btMTuwYHgUQ85k4ov4Xjz5SNpAGgemig5G5w7PJj4NhGvIBz9weL154x/BFVjHOZZ6Y/bWgJIPoW1KM15x5K8QylWYEBUHtwiyVyXOxHqt6MOX1vYo1L37jMK88IErrfh/VmlxEhtN9wOghk8IudMfFwQtjIwiWlJf218wxMIzUjoyb5/25tU9f2OJrg=

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ all: vet test postgres_exporter
77

88
# Simple go build
99
postgres_exporter: $(GO_SRC)
10-
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=git:$(shell git rev-parse HEAD)" -o postgres_exporter .
10+
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(shell git describe --dirty)" -o postgres_exporter .
11+
12+
postgres_exporter_integration_test: $(GO_SRC)
13+
CGO_ENABLED=0 go test -c -tags integration \
14+
-a -ldflags "-extldflags '-static' -X main.Version=git:$(shell git describe --dirty)" -o postgres_exporter_integration_test .
1115

1216
# Take a go build and turn it into a minimal container
1317
docker: postgres_exporter
@@ -19,8 +23,8 @@ vet:
1923
test:
2024
go test -v .
2125

22-
test-integration:
23-
tests/test-smoke
26+
test-integration: postgres_exporter postgres_exporter_integration_test
27+
tests/test-smoke ./postgres_exporter ./postgres_exporter_integration_test
2428

2529
# Do a self-contained docker build - we pull the official upstream container
2630
# and do a self-contained build.

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
3434

3535
### Flags
3636

37-
Name | Description
38-
-------------------|------------
39-
web.listen-address | Address to listen on for web interface and telemetry.
40-
web.telemetry-path | Path under which to expose metrics.
37+
* `web.listen-address`
38+
Address to listen on for web interface and telemetry.
39+
40+
* `web.telemetry-path`
41+
Path under which to expose metrics.
42+
43+
* `config.expect-replication-stats`
44+
The target database has replication turned on - log errors when
45+
replication stats are missing.
4146

4247
### Setting the Postgres server's data source name
4348

postgres_exporter.go

Lines changed: 537 additions & 244 deletions
Large diffs are not rendered by default.

postgres_exporter_integration_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// These are specialized integration tests. We only build them when we're doing
2+
// a lot of additional work to keep the external docker environment they require
3+
// working.
4+
// +build integration
5+
6+
package main
7+
8+
import (
9+
"os"
10+
"testing"
11+
12+
. "gopkg.in/check.v1"
13+
14+
"github.com/prometheus/client_golang/prometheus"
15+
"database/sql"
16+
_ "github.com/lib/pq"
17+
"fmt"
18+
)
19+
20+
// Hook up gocheck into the "go test" runner.
21+
func Test(t *testing.T) { TestingT(t) }
22+
23+
type IntegrationSuite struct{
24+
e *Exporter
25+
}
26+
27+
var _ = Suite(&IntegrationSuite{})
28+
29+
func (s *IntegrationSuite) SetUpSuite(c *C) {
30+
dsn := os.Getenv("DATA_SOURCE_NAME")
31+
c.Assert(dsn, Not(Equals), "")
32+
33+
exporter := NewExporter(dsn, "")
34+
c.Assert(exporter, NotNil)
35+
// Assign the exporter to the suite
36+
s.e = exporter
37+
38+
prometheus.MustRegister(exporter)
39+
}
40+
41+
// TODO: it would be nice if this didn't mostly just recreate the scrape function
42+
func (s *IntegrationSuite) TestAllNamespacesReturnResults(c *C) {
43+
// Setup a dummy channel to consume metrics
44+
ch := make(chan prometheus.Metric, 100)
45+
go func() {
46+
for _ = range ch {}
47+
}()
48+
49+
// Open a database connection
50+
db, err := sql.Open("postgres", s.e.dsn)
51+
c.Assert(db, NotNil)
52+
c.Assert(err, IsNil)
53+
defer db.Close()
54+
55+
// Do a version update
56+
err = s.e.checkMapVersions(ch, db)
57+
c.Assert(err, IsNil)
58+
59+
// Check the show variables work
60+
nonFatalErrors := queryShowVariables(ch, db, s.e.variableMap)
61+
if !c.Check(len(nonFatalErrors), Equals, 0) {
62+
fmt.Println("## NONFATAL ERRORS FOUND")
63+
for _, err := range nonFatalErrors {
64+
fmt.Println(err)
65+
}
66+
}
67+
68+
69+
// This should never happen in our test cases.
70+
errMap := queryNamespaceMappings(ch, db, s.e.metricMap, s.e.queryOverrides)
71+
if !c.Check(len(errMap), Equals, 0) {
72+
fmt.Println("## NAMESPACE ERRORS FOUND")
73+
for namespace, err := range errMap {
74+
fmt.Println(namespace, ":", err)
75+
}
76+
}
77+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM postgres:9.6
2+
MAINTAINER Daniel Dent (https://www.danieldent.com)
3+
ENV PG_MAX_WAL_SENDERS 8
4+
ENV PG_WAL_KEEP_SEGMENTS 8
5+
COPY setup-replication.sh /docker-entrypoint-initdb.d/
6+
COPY docker-entrypoint.sh /docker-entrypoint.sh
7+
RUN chmod +x /docker-entrypoint-initdb.d/setup-replication.sh /docker-entrypoint.sh
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM postgres:{{VERSION}}
2+
MAINTAINER Daniel Dent (https://www.danieldent.com)
3+
ENV PG_MAX_WAL_SENDERS 8
4+
ENV PG_WAL_KEEP_SEGMENTS 8
5+
COPY setup-replication.sh /docker-entrypoint-initdb.d/
6+
COPY docker-entrypoint.sh /docker-entrypoint.sh
7+
RUN chmod +x /docker-entrypoint-initdb.d/setup-replication.sh /docker-entrypoint.sh
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Replicated postgres cluster in docker.
2+
3+
Upstream is forked from https://github.com/DanielDent/docker-postgres-replication
4+
5+
My version lives at https://github.com/wrouesnel/docker-postgres-replication
6+
7+
This very simple docker-compose file lets us stand up a replicated postgres
8+
cluster so we can test streaming.
9+
10+
# TODO:
11+
Pull in p2 and template the Dockerfile so we can test multiple versions.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
version: '2'
3+
4+
services:
5+
pg-master:
6+
build: '.'
7+
image: 'danieldent/postgres-replication'
8+
restart: 'always'
9+
environment:
10+
POSTGRES_USER: 'postgres'
11+
POSTGRES_PASSWORD: 'postgres'
12+
PGDATA: '/var/lib/postgresql/data/pgdata'
13+
volumes:
14+
- '/var/lib/postgresql/data'
15+
expose:
16+
- '5432'
17+
18+
pg-slave:
19+
build: '.'
20+
image: 'danieldent/postgres-replication'
21+
restart: 'always'
22+
environment:
23+
POSTGRES_USER: 'postgres'
24+
POSTGRES_PASSWORD: 'postgres'
25+
PGDATA: '/var/lib/postgresql/data/pgdata'
26+
REPLICATE_FROM: 'pg-master'
27+
volumes:
28+
- '/var/lib/postgresql/data'
29+
expose:
30+
- '5432'
31+
links:
32+
- 'pg-master'

0 commit comments

Comments
 (0)