Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Configurable publicorgid #883

Merged
merged 3 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker/docker-chaos/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1s

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-cluster/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1s

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-dev-custom-cfg-kafka/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1h

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down
3 changes: 3 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ gc-interval = 1h
# shorter warmup means metrictank will need to query cassandra more if it doesn't have requested data yet.
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1h
# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0
```

## metric data storage in cassandra ##
Expand Down
6 changes: 3 additions & 3 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ POST /metrics/index.json

* header `X-Org-Id` required

Returns metrics stored under the given org, as well as public data under org 0 (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))
Returns metrics stored under the given org, as well as public data (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))

#### Example

Expand All @@ -56,7 +56,7 @@ POST /metrics/find
* format: json, treejson, completer, pickle, or msgpack. (defaults to json)
* jsonp

Returns metrics which match the query and are stored under the given org or are public data under org 0 (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))
Returns metrics which match the query and are stored under the given org or are public data (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))
the completer format is for completion UI's such as graphite-web.
json and treejson are the same.

Expand Down Expand Up @@ -112,7 +112,7 @@ POST /render

If metrictank doesn't have a requested function, it always proxies to graphite, irrespective of this setting.

Data queried for must be stored under the given org or be public data under org 0 (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))
Data queried for must be stored under the given org or be public data (see [multi-tenancy](https://github.com/grafana/metrictank/blob/master/docs/multi-tenancy.md))

#### Example

Expand Down
2 changes: 1 addition & 1 deletion docs/multi-tenancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ A metrictank based stack is multi-tenant. Here's how it works:
* For a secure setup, you must make sure these headers cannot be specified by users. You may need to run something in front to set the header correctly after authentication
(e.g. [tsdb-gw](https://github.com/raintank/tsdb-gw)
* orgs can only see the data that lives under their org-id, and also public data
* public data is stored under orgId 0 and is visible to everyone.
* using the `public-org` setting, you can specify an org-id which holds public data.
2 changes: 1 addition & 1 deletion idx/idx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
schema "gopkg.in/raintank/schema.v1"
)

const OrgIdPublic = 0
var OrgIdPublic = 0

var (
BothBranchAndLeaf = errors.New("node can't be both branch and leaf")
Expand Down
2 changes: 1 addition & 1 deletion idx/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ func (m *MemoryIdx) Find(orgId int, pattern string, from int64) ([]idx.Node, err
if err != nil {
return nil, err
}
if orgId != idx.OrgIdPublic {
if orgId != idx.OrgIdPublic && idx.OrgIdPublic > 0 {
publicNodes, err := m.find(idx.OrgIdPublic, pattern)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions metrictank-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1h

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down
7 changes: 7 additions & 0 deletions metrictank.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
metricMaxStaleStr = flag.String("metric-max-stale", "6h", "max age for a metric before to be considered stale and to be purged from memory.")
gcIntervalStr = flag.String("gc-interval", "1h", "Interval to run garbage collection job.")
warmUpPeriodStr = flag.String("warm-up-period", "1h", "duration before secondary nodes start serving requests")
publicOrg = flag.Int("public-org", 0, "org Id for publically (any org) accessible data. leave 0 to disable")

// Cassandra:
cassandraAddrs = flag.String("cassandra-addrs", "localhost", "cassandra host (may be given multiple times as comma-separated list)")
Expand Down Expand Up @@ -323,6 +324,12 @@ func main() {
***********************************/
pre := time.Now()

if *publicOrg < 0 {
log.Fatal(4, "public-org cannot be <0")
}

idx.OrgIdPublic = *publicOrg

if memory.Enabled {
if metricIndex != nil {
log.Fatal(4, "Only 1 metricIndex handler can be enabled.")
Expand Down
4 changes: 4 additions & 0 deletions scripts/config/metrictank-docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1h

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down
4 changes: 4 additions & 0 deletions scripts/config/metrictank-package.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gc-interval = 1h
# in clusters, best to assure the primary has saved all the data that a newly warmup instance will need to query, to prevent gaps in charts
warm-up-period = 1h

# org Id for publically (any org) accessible data
# leave at 0 to disable.
public-org = 0

## metric data storage in cassandra ##

# see https://github.com/grafana/metrictank/blob/master/docs/cassandra.md for more details
Expand Down