Skip to content

Commit

Permalink
Merge pull request ClickHouse#18 from AlekSi/promu-and-travis
Browse files Browse the repository at this point in the history
Use Docker Compose in Travis CI
  • Loading branch information
f1yegor committed Oct 27, 2017
2 parents e87bb21 + 6b253dc commit 8e6dc2b
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 83 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.build/
clickhouse_exporter
.idea
.build
coverage.txt
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ build:
prefix: .
binaries:
- name: clickhouse_exporter
path: .
path: .
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ language: go

go:
- 1.8.x
- 1.9.x
- master

go_import_path: github.com/f1yegor/clickhouse_exporter

services:
- docker

before_script:
- PACKAGES=`go list ./... | grep -v vendor`
- go get github.com/prometheus/promu
- go get github.com/AlekSi/gocoverutil
- docker --version
- docker-compose --version
- docker-compose up -d

- make init

script:
- promu build
# - gocoverutil test -v $PACKAGES
- make

after_success:
# - bash <(curl -s https://codecov.io/bash) -X fix
- bash <(curl -s https://codecov.io/bash) -X fix
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

## Local setup

The easiest way to make a local development setup is to use Docker Compose: `make env-run` on Linux.
The easiest way to make a local development setup is to use Docker Compose.

You can run ClickHouse client with `make clickhouse-client`.
```
docker-compose up
make init
make
```


## Vendoring

We use [dep](https://github.com/golang/dep) to vendor dependencies. Please use released version, i.e. do not `go get`
from `master` branch.
from `master` branch.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: build test

init:
go get -u github.com/prometheus/promu
go get -u github.com/AlekSi/gocoverutil

build:
go install -v
promu build

test:
go test -v -race
gocoverutil -coverprofile=coverage.txt test -v
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Clickhouse Exporter for Prometheus

[![Build Status](https://travis-ci.org/f1yegor/clickhouse_exporter.svg?branch=master)](https://travis-ci.org/f1yegor/clickhouse_exporter)
[![Go Report Card](https://goreportcard.com/badge/github.com/f1yegor/clickhouse_exporter)](https://goreportcard.com/report/github.com/f1yegor/clickhouse_exporter)

This is a simple server that periodically scrapes ClickHouse(https://clickhouse.yandex/) stats and exports them via HTTP for Prometheus(https://prometheus.io/)
consumption.

Expand All @@ -16,12 +19,12 @@ Help on flags:

Credentials(if not default):

via environment variables
via environment variables
```
CLICKHOUSE_USER
CLICKHOUSE_PASSWORD
```

## Using Docker

```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1
0.1
5 changes: 3 additions & 2 deletions clickhouse_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"sync"
"unicode"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
"os"
)

const (
Expand Down Expand Up @@ -353,7 +353,8 @@ func toSnake(in string) string {
return string(out)
}

//var _ Exporter = (*prometheus.Collector)(nil)
// check interface
var _ prometheus.Collector = (*Exporter)(nil)

func main() {
flag.Parse()
Expand Down
70 changes: 24 additions & 46 deletions clickhouse_exporter_test.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,39 @@
package main

import (
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/prometheus/client_golang/prometheus"
)

const (
clickhouseMetrics = `Query 1
Merge 0
ReplicatedFetch 0
ReplicatedSend 0
ReplicatedChecks 0
BackgroundPoolTask 0
DiskSpaceReservedForMerge 0
DistributedSend 0
QueryPreempted 0
TCPConnection 0
HTTPConnection 1
InterserverConnection 0
OpenFileForRead 0
OpenFileForWrite 0
Read 1
Write 0
SendExternalTables 0
QueryThread 0
ReadonlyReplica 0
MemoryTracking 8704
`
metricCount = 20
)
func TestScrape(t *testing.T) {
url, err := url.Parse("http://127.0.0.1:8123/")
if err != nil {
t.Fatal(err)
}
exporter := NewExporter(*url)

func TestClickhouseStatus(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(clickhouseMetrics))
t.Run("Describe", func(t *testing.T) {
ch := make(chan *prometheus.Desc)
go func() {
exporter.Describe(ch)
close(ch)
}()

for range ch {
}
})
server := httptest.NewServer(handler)

url, _ := url.Parse(server.URL)
e := NewExporter(*url)
ch := make(chan prometheus.Metric)
t.Run("Collect", func(t *testing.T) {
ch := make(chan prometheus.Metric)
var err error
go func() {
err = exporter.collect(ch)
close(ch)
}()

go func() {
defer close(ch)
e.Collect(ch)
}()
// because asks 3 tables
for i := 1; i <= 3*metricCount; i++ {
m := <-ch
if m == nil {
t.Error("expected metric but got nil")
for range ch {
}
}
if <-ch != nil {
t.Error("expected closed channel")
}
})
}
19 changes: 0 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
---
version: '3'
services:
prometheus:
image: prom/prometheus:v2.0.0-beta.2
ports:
- 127.0.0.1:9090:9090
network_mode: host
volumes:
- ./docker/prometheus:/etc/prometheus

clickhouse:
image: yandex/clickhouse-server
ports:
- 127.0.0.1:8123:8123
- 127.0.0.1:9000:9000
- 127.0.0.1:9009:9009
network_mode: host
# volumes:
# - ./config.xml:/etc/clickhouse-server/config.xml
# - ./users.xml:/etc/clickhouse-server/users.xml

clickhouse_exporter:
image: f1yegor/clickhouse-exporter
ports:
- 127.0.0.1:9116:9116
network_mode: host
command: -scrape_uri=http://127.0.0.1:8123/
2 changes: 1 addition & 1 deletion docker/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ scrape_configs:

- job_name: clickhouse
static_configs:
- targets: ['127.0.0.1:9116']
- targets: ['127.0.0.1:9116']

0 comments on commit 8e6dc2b

Please sign in to comment.