Skip to content

Commit e6782af

Browse files
author
Heiko Zuerker
authored
Build and release automation (#3)
* Allow configuration through environment variables * Use nonroot image, require parameters, add version parameter * Adding config for build automation * Add config to release to quay.io * Update documentation and add image build
1 parent 7c94eee commit e6782af

File tree

12 files changed

+244
-26
lines changed

12 files changed

+244
-26
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage.txt
2+
dist/
3+
prometheus_bigquery_remote_storage_adapter
4+
.idea
5+
*.swp
6+
.vscode

.goreleaser.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This is an example goreleaser.yaml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
project_name: prometheus_bigquery_remote_storage_adapter
4+
env:
5+
- CGO_ENABLED=0
6+
before:
7+
hooks:
8+
- go mod tidy
9+
builds:
10+
- ldflags:
11+
- "-X {{.Env.VERSION_PKG}}.Branch={{.Env.BRANCH}}"
12+
- "-X {{.Env.VERSION_PKG}}.BuildDate={{.Env.DATE}}"
13+
- "-X {{.Env.VERSION_PKG}}.GitSHA1={{.Env.COMMIT}}"
14+
archives:
15+
- replacements:
16+
darwin: Darwin
17+
linux: Linux
18+
windows: Windows
19+
386: i386
20+
amd64: x86_64
21+
checksum:
22+
name_template: 'checksums.txt'
23+
snapshot:
24+
name_template: "{{ .Tag }}-next"
25+
changelog:
26+
skip: true
27+
dockers:
28+
- binaries:
29+
- prometheus_bigquery_remote_storage_adapter
30+
image_templates:
31+
- "quay.io/kohlstechnology/{{.ProjectName}}:{{ .Tag }}"
32+
- "quay.io/kohlstechnology/{{.ProjectName}}:latest"
33+
build_flag_templates:
34+
- "--label=org.opencontainers.image.created={{.Date}}"
35+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
36+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
37+
- "--label=org.opencontainers.image.version={{.Version}}"

.travis.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1-
---
2-
language: minimal
3-
1+
branches:
2+
only:
3+
- master
4+
- "/^v\\d+\\.\\d+\\.\\d+$/"
5+
sudo: required
6+
language: go
7+
matrix:
8+
include:
9+
- go: 1.14.x
10+
env:
11+
global:
12+
- secure: j/acmH3CpQSsD13ofSnuqAEBzFE5SB6v1Sk0+ICXgTeJrzz+N3ohJBiRa10MuEn5+QcFYPF8oGefTbgWVb7iHEMbBI60HQqoLQ7817CDJWxn5nywlE/79IVUuBn+S+TgCXOyj+AG6+4HiRIwCzKDBqIy+TOPs7HH7Tryvhjiu5ievM8wM0+SfElO4BMIZbreCiFpv6at1oUPLSU2G4x6VJ242lXCVdeHCcYahDymA55CQtT1whoutUzDTWbB5YXu7/8IaT+pXl5YicuK1lvxZoJogl+uh58COwWKtWeqxEkvzzRoUjhuIzdNRNldCstVTXDCInZhwEc05e1qddVLluVko2nlQM99e80Llhurg3kK0tgGxA5OpWY/WzEODOY8vyDdCf7Oe/+llNVKyUxnwoDcmHB26Geugoi284Fzqn7qcZMngYvwmxsYcAbkIFfnnNA4FPXwA9556En+bZNX881y6NWyM1rZPnvHHKsPfnszzbZXfXhHzRygLqcn8YczaBzO6AHmbrBva5IrwGBIr372IP2hRvK+UXSUGqO5rCfXHznb5C2A6ew+7eyl9CGCsBw1NoWB76ebsNii1j4O3eLXKBckTRYfAq7+b0fS1HSNZjzVB14Xg2X4JczD5t8FK3d2Z24k6PR/N12QlfZtyEAmxsJG6xWlm1hA87mVQDQ=
13+
- secure: F7xb26+IrXNAnh4gV8im/ZfzYdpwy/1X4bDHZE+1mwlHZi3d0POWZVh2gEYzGXTV5TW7I1VaBiLoHktcwe/+a643Op1CwkS2widg06PpspM8BCH1PQXhNwuM5oyX08dI46ak9XWGbFfDUDxYqG2dnbrX2A348/BcF1WPTVb1KLyPXY9PUsS/0dodyZy+f6DeFaaYet60iMCBtO+JbaZvLV8wK6RRMNEKS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ruya2rwkPa2I0ZH3B47iIQb/UrD6Y/xoI2mAZWbq0J6KaVu4HxMxpH2+j9h35EXSeVAwUxq3sb/WJi8=
15+
matrix:
16+
- GO_RELEASER_VERSION=v0.129.0
17+
services:
18+
- docker
19+
before_install:
20+
- GO111MODULE=off go get golang.org/x/lint/golint
21+
- curl -L -o /tmp/goreleaser.tar.gz https://github.com/goreleaser/goreleaser/releases/download/${GO_RELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz
22+
- sudo tar -xzf /tmp/goreleaser.tar.gz -C /usr/local/bin/ && sudo chmod +x /usr/local/bin/goreleaser
423
install:
5-
- # skip
6-
24+
-
725
script:
8-
- echo hello, world!
9-
26+
- make test-dirty
27+
- make test-release
28+
after_success:
29+
- test -n "$TRAVIS_TAG" && docker login -u="$QUAYIO_USER" -p="$QUAYIO_SECRET" quay.io
30+
deploy:
31+
- provider: script
32+
skip_cleanup: true
33+
script: make clean release
34+
on:
35+
tags: true
36+
condition: "$TRAVIS_OS_NAME = linux"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## v0.1.0 (March 31, 2020)
2+
* Initial release

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM gcr.io/distroless/static:nonroot
2+
3+
COPY ./prometheus_bigquery_remote_storage_adapter /bigquery_remote_storage_adapter
4+
5+
EXPOSE 9201
6+
7+
ENTRYPOINT ["/bigquery_remote_storage_adapter"]

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LDFLAGS := "-X ${VERSION_PKG}.Branch=${BRANCH} -X ${VERSION_PKG}.BuildDate=${DAT
88
TAG?=""
99

1010
.PHONY: all
11-
all: build
11+
all: build image
1212

1313
.PHONY: clean
1414
clean:
@@ -18,6 +18,10 @@ clean:
1818
build:
1919
CGO_ENABLED=0 go build -o $(BINARY) -ldflags $(LDFLAGS)
2020

21+
.PHONY: image
22+
image:
23+
docker build . -t quay.io/kohlstechnology/prometheus_bigquery_remote_storage_adapter:latest
24+
2125
.PHONY: test
2226
test: fmt vet test-unit
2327

README.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# BigQuery Remote Storage Adapter for Prometheus
22

3+
[![Build Status](https://travis-ci.com/KohlsTechnology/prometheus_bigquery_remote_storage_adapter.svg?branch=master)](https://travis-ci.com/KohlsTechnology/prometheus_bigquery_remote_storage_adapter)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/KohlsTechnology/prometheus_bigquery_remote_storage_adapter)](https://goreportcard.com/report/github.com/KohlsTechnology/prometheus_bigquery_remote_storage_adapter)
5+
[![Docker Repository on Quay](https://quay.io/repository/kohlstechnology/prometheus_bigquery_remote_storage_adapter/status "Docker Repository on Quay")](https://quay.io/repository/kohlstechnology/prometheus_bigquery_remote_storage_adapter)
6+
37
This is a write adapter that receives samples via Prometheus's remote write protocol and stores them in Google BigQuery. This adapter is based off code found in the official prometheus repo:
48

59
https://github.com/prometheus/prometheus/tree/master/documentation/examples/remote_storage/remote_storage_adapter
@@ -8,7 +12,6 @@ Remote read is not currently supported by this adapter.
812

913
Billing MUST be enabled on the GCP project with the destination BigQuery tables. This adapter uses the "streaming inserts" API. More information is available here: https://cloud.google.com/bigquery/streaming-data-into-bigquery#before_you_begin
1014

11-
1215
The table schema in BigQuery should be the following format:
1316

1417
| Field name | Type | Mode |
@@ -18,7 +21,6 @@ The table schema in BigQuery should be the following format:
1821
| value | FLOAT | NULLABLE |
1922
| timestamp | TIMESTAMP | NULLABLE |
2023

21-
2224
It is recommended that the BigQuery table is partitioned on the timestamp column for performance.
2325

2426
The tags field is a json string and can be easily extracted. Here is an example query:
@@ -30,13 +32,7 @@ SELECT metricname, tags, JSON_EXTRACT(tags, '$.some_label')
3032
WHERE JSON_EXTRACT(tags, '$.some_label') = "\\"target_label_value\\""
3133
```
3234

33-
## Building
34-
35-
```
36-
go build
37-
```
38-
39-
## Running
35+
## Running directly
4036

4137
```
4238
./bigquery_remote_storage_adapter \
@@ -51,6 +47,19 @@ To show all flags:
5147
./bigquery_remote_storage_adapter -h
5248
```
5349

50+
## Configuration
51+
52+
You can configure this storage adapter either through command line options or environment variables. The later is required if you're using our docker image.
53+
54+
| Command Line Flag | Environment Variable | Required | Default | Description |
55+
| --- | --- | --- | --- | --- |
56+
| `--googleAPIjsonkeypath` | `PROMBQ_GCP_JSON` | Yes | | Path to json keyfile for GCP service account. JSON keyfile also contains project_id. |
57+
| `--googleAPIdatasetID` | `PROMBQ_DATASET` | Yes | | Dataset name as shown in GCP |
58+
| `--googleAPItableID` | `PROMBQ_TABLE` | Yes | | Table name as showon in GCP |
59+
| `--send-timeout` | `PROMBQ_TIMEOUT` | No | `30s` | The timeout to use when sending samples to the remote storage |
60+
| `--web.listen-address` | `PROMBQ_LISTEN` | No | `:9201` | Address to listen on for web endpoints |
61+
| `--web.telemetry-path` | `PROMBQ_TELEMETRY` | No | `/metrics` | Address to listen on for web endpoints |
62+
5463
## Configuring Prometheus
5564

5665
To configure Prometheus to send samples to this binary, add the following to your `prometheus.yml`:
@@ -61,3 +70,43 @@ remote_write:
6170
- url: "http://localhost:9201/write"
6271

6372
```
73+
74+
## Building
75+
76+
### Binary
77+
78+
If you just need a local version to test, then the simplest way is to execute:
79+
80+
```
81+
make build
82+
```
83+
84+
### Image
85+
86+
In order to build the docker image, simply execute
87+
88+
```
89+
make image
90+
```
91+
92+
## Releasing
93+
94+
This project is using [goreleaser](https://goreleaser.com). GitHub release creation is automated using Travis
95+
CI. New releases are automatically created when new tags are pushed to the repo.
96+
```
97+
$ TAG=v0.0.2 make tag
98+
```
99+
100+
How to manually create a release without relying on Travis CI.
101+
```
102+
$ TAG=v0.0.2 make tag
103+
$ GITHUB_TOKEN=xxx make clean release
104+
```
105+
106+
### Testing
107+
108+
You can execute goreleaser locally in order to test any changes.
109+
110+
```
111+
make clean test-release
112+
```

bigquerydb/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func NewClient(logger log.Logger, googleAPIjsonkeypath, googleAPIdatasetID, goog
5656
var result map[string]interface{}
5757
json.Unmarshal([]byte(byteValue), &result)
5858

59-
//fmt.Println(result["type"])
6059
jsonFile.Close()
6160

6261
projectID := fmt.Sprintf("%v", result["project_id"])

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/ReliabilityEngineering/prometheus_bigquery_remote_storage_adapter
1+
module github.com/KohlsTechnology/prometheus_bigquery_remote_storage_adapter
22

33
go 1.14
44

0 commit comments

Comments
 (0)