Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Jun 16, 2022
1 parent 7c225c8 commit 94cec93
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) {

rc.objStoreConfig = extkingpin.RegisterCommonObjStoreFlags(cmd, "", false)

rc.retention = extkingpin.ModelDuration(cmd.Flag("tsdb.retention", "How long to retain raw samples on local storage. 0d - disables this retention.").Default("15d"))
rc.retention = extkingpin.ModelDuration(cmd.Flag("tsdb.retention", "How long to retain raw samples on local storage. 0d - disables this retention. For more details on how retention is enforced for individual tenants, please refer to the Tenant lifecycle management section in the Receive documentation.").Default("15d"))

cmd.Flag("receive.hashrings-file", "Path to file that contains the hashring configuration. A watcher is initialized to watch changes and update the hashring dynamically.").PlaceHolder("<path>").StringVar(&rc.hashringsFilePath)

Expand Down
6 changes: 5 additions & 1 deletion docs/components/receive.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ Flags:
next startup.
--tsdb.path="./data" Data directory of TSDB.
--tsdb.retention=15d How long to retain raw samples on local
storage. 0d - disables this retention.
storage. 0d - disables this retention. For more
details on how retention is enforced for
individual tenants, please refer to the Tenant
lifecycle management section in the Receive
documentation.
--tsdb.wal-compression Compress the tsdb WAL.
--version Show application version.
Expand Down
35 changes: 35 additions & 0 deletions hack/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
global:
scrape_interval: 15s
external_labels:
replica: "1"

remote_write:
- url: http://receiver-2:19291/api/v1/receive
headers:
THANOS-TENANT: prometheus
write_relabel_configs:
- source_labels:
- job
regex: prometheus
action: keep

- url: http://receiver-2:19291/api/v1/receive
headers:
THANOS-TENANT: receiver
write_relabel_configs:
- source_labels:
- job
regex: receivers
action: keep

scrape_configs:
- job_name: 'prometheus'
scrape_interval: 10s
static_configs:
- targets: [ 'localhost:9090' ]

- job_name: 'receivers'
scrape_interval: 10s
static_configs:
- targets: [ 'receiver-1:10902', 'receiver-2:10902', 'receiver-3:10902' ]

110 changes: 110 additions & 0 deletions hack/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
version: "2"

services:

# minio:
# image: minio/minio:latest
# command:
# - server
# - /data
# - --console-address=:9001
# ports:
# - "9000:9000"
# - "9001:9001"
# volumes:
# - bucket:/data

# compactor:
# image: thanos:latest
# depends_on:
# minio:
# condition: service_started
# command:
# - compact
# - --objstore.config-file=/var/receive/s3.yml
# - --wait
# - --delete-delay=10m
# - --consistency-delay=0s
# - --log.level=debug
# volumes:
# - ./s3.yml:/var/receive/s3.yml
# ports:
# - "10903:10902"

prometheus:
image: prom/prometheus:latest
command:
- --config.file=/var/prometheus/config.yml
- --web.enable-admin-api
volumes:
- ./config.yml:/var/prometheus/config.yml
ports:
- "9090:9090"

receiver-1:
image: thanos:latest
command:
- receive
- --label=receive_replica="shard-1"
- --grpc-address=0.0.0.0:10901
- --receive.local-endpoint=receiver-1:10901
- --tsdb.min-block-duration=2m
- --tsdb.max-block-duration=2m
- --tsdb.retention=5m
# - --receive.hashrings-algorithm=consistent
- --receive.hashrings-file=/var/receive/hashrings.json
- --receive.replication-factor=2
# - --objstore.config-file=/var/receive/s3.yml
volumes:
- ./hashrings.json:/var/receive/hashrings.json
- ./s3.yml:/var/receive/s3.yml

receiver-2:
image: thanos:latest
command:
- receive
- --label=receive_replica="shard-2"
- --grpc-address=0.0.0.0:10901
- --tsdb.min-block-duration=2m
- --tsdb.max-block-duration=2m
- --tsdb.retention=5m
# - --receive.hashrings-algorithm=consistent
- --receive.local-endpoint=receiver-2:10901
- --receive.hashrings-file=/var/receive/hashrings.json
- --receive.replication-factor=2
# - --objstore.config-file=/var/receive/s3.yml
volumes:
- ./hashrings.json:/var/receive/hashrings.json
- ./s3.yml:/var/receive/s3.yml

receiver-3:
image: thanos:latest
command:
- receive
- --label=receive_replica="shard-3"
- --grpc-address=0.0.0.0:10901
- --tsdb.min-block-duration=2m
- --tsdb.max-block-duration=2m
- --tsdb.retention=5m
# - --receive.hashrings-algorithm=consistent
- --receive.local-endpoint=receiver-3:10901
- --receive.hashrings-file=/var/receive/hashrings.json
- --receive.replication-factor=2
# - --objstore.config-file=/var/receive/s3.yml
volumes:
- ./hashrings.json:/var/receive/hashrings.json
- ./s3.yml:/var/receive/s3.yml

query:
image: thanos:latest
command:
- query
- --endpoint=receiver-1:10901
- --endpoint=receiver-2:10901
- --endpoint=receiver-3:10901
- --query.replica-label=receive_replica
ports:
- "10902:10902"

volumes:
bucket: {}
11 changes: 11 additions & 0 deletions hack/hashrings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"hashring": "remote-write",
"endpoints": ["receiver-1:10901", "receiver-3:10901"],
"tenants": ["prometheus"]
},
{
"hashring": "remote-write",
"endpoints": ["receiver-1:10901", "receiver-2:10901"],
"tenants": ["receiver"]
}]
7 changes: 7 additions & 0 deletions hack/s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: S3
config:
bucket: "receiver"
endpoint: "minio:9000"
access_key: minioadmin
insecure: true
secret_key: minioadmin
5 changes: 5 additions & 0 deletions pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ func (t *MultiTSDB) Close() error {
// Prune flushes and closes the TSDB for tenants that haven't received
// any new samples for longer than the TSDB retention period.
func (t *MultiTSDB) Prune(ctx context.Context) error {
// Retention of 0 means infinite retention.
if t.tsdbOpts.RetentionDuration == 0 {
return nil
}

t.mtx.Lock()
defer t.mtx.Unlock()

Expand Down

0 comments on commit 94cec93

Please sign in to comment.