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

Schema templates + scylladb docker stack #898

Merged
merged 7 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/mt-index-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/gocql/gocql"
"github.com/grafana/metrictank/cluster/partitioner"
"github.com/grafana/metrictank/idx/cassandra"
"github.com/grafana/metrictank/util"
"github.com/raintank/worldping-api/pkg/log"
"gopkg.in/raintank/schema.v1"
)
Expand All @@ -23,6 +23,7 @@ var (
dstKeyspace = flag.String("dst-keyspace", "raintank", "Cassandra keyspace in use on destination.")
partitionScheme = flag.String("partition-scheme", "byOrg", "method used for partitioning metrics. (byOrg|bySeries)")
numPartitions = flag.Int("num-partitions", 1, "number of partitions in cluster")
schemaFile = flag.String("schema-file", "/etc/metrictank/schema-idx-cassandra.toml", "File containing the needed schemas in case database needs initializing")

wg sync.WaitGroup
)
Expand Down Expand Up @@ -64,7 +65,8 @@ func main() {
}

// ensure the dest table exists.
err = dstSession.Query(fmt.Sprintf(cassandra.TableSchema, *dstKeyspace)).Exec()
schemaTable := util.ReadEntry(*schemaFile, "schema_table").(string)
err = dstSession.Query(fmt.Sprintf(schemaTable, *dstKeyspace)).Exec()
if err != nil {
log.Fatal(4, "cassandra-idx failed to initialize cassandra table. %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/mt-split-metrics-by-ttl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
cassandraRetries = flag.Int("cassandra-retries", 0, "how many times to retry a query before failing it")
cqlProtocolVersion = flag.Int("cql-protocol-version", 4, "cql protocol version to use")
cassandraCreateKeyspace = flag.Bool("cassandra-create-keyspace", true, "enable the creation of the metrictank keyspace")
cassandraSchemaFile = flag.String("cassandra-schema-file", "/etc/metrictank/schema-store-cassandra.toml", "File containing the needed schemas in case database needs initializing")

cassandraSSL = flag.Bool("cassandra-ssl", false, "enable SSL connection to cassandra")
cassandraCaPath = flag.String("cassandra-ca-path", "/etc/metrictank/ca.pem", "cassandra CA certificate path when using SSL")
Expand Down Expand Up @@ -69,7 +70,7 @@ func main() {
panic(fmt.Sprintf("Error creating directory: %s", err))
}

store, err := cassandra.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, cassandraReadConcurrency, cassandraReadConcurrency, cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, windowFactor, cassandraOmitReadTimeout, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, ttls)
store, err := cassandra.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, cassandraReadConcurrency, cassandraReadConcurrency, cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, windowFactor, cassandraOmitReadTimeout, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, *cassandraSchemaFile, ttls)
if err != nil {
panic(fmt.Sprintf("Failed to instantiate cassandra: %s", err))
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/mt-store-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
cassandraRetries = flag.Int("cassandra-retries", 0, "how many times to retry a query before failing it")
cqlProtocolVersion = flag.Int("cql-protocol-version", 4, "cql protocol version to use")
cassandraCreateKeyspace = flag.Bool("cassandra-create-keyspace", true, "enable the creation of the metrictank keyspace")
cassandraSchemaFile = flag.String("cassandra-schema-file", "/etc/metrictank/schema-store-cassandra.toml", "File containing the needed schemas in case database needs initializing")

cassandraSSL = flag.Bool("cassandra-ssl", false, "enable SSL connection to cassandra")
cassandraCaPath = flag.String("cassandra-ca-path", "/etc/metrictank/ca.pem", "cassandra CA certificate path when using SSL")
Expand Down Expand Up @@ -162,7 +163,7 @@ func main() {
}
}

store, err := cassandra.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, *cassandraReadConcurrency, *cassandraReadConcurrency, *cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, *windowFactor, *cassandraOmitReadTimeout, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, nil)
store, err := cassandra.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, *cassandraReadConcurrency, *cassandraReadConcurrency, *cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, *windowFactor, *cassandraOmitReadTimeout, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, *cassandraSchemaFile, nil)
if err != nil {
log.Fatal(4, "failed to initialize cassandra. %s", err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/mt-whisper-importer-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ var (
cassandraUsername = globalFlags.String("cassandra-username", "cassandra", "username for authentication")
cassandraPassword = globalFlags.String("cassandra-password", "cassandra", "password for authentication")

cassandraSchemaFile = flag.String("cassandra-schema-file", "/etc/metrictank/schema-store-cassandra.toml", "File containing the needed schemas in case database needs initializing")

gitHash = "(none)"
)

Expand Down Expand Up @@ -151,7 +153,7 @@ func main() {
log.SetLevel(log.InfoLevel)
}

store, err := cassandraStore.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, *cassandraReadConcurrency, *cassandraReadConcurrency, *cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, *windowFactor, 60, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, nil)
store, err := cassandraStore.NewCassandraStore(*cassandraAddrs, *cassandraKeyspace, *cassandraConsistency, *cassandraCaPath, *cassandraUsername, *cassandraPassword, *cassandraHostSelectionPolicy, *cassandraTimeout, *cassandraReadConcurrency, *cassandraReadConcurrency, *cassandraReadQueueSize, 0, *cassandraRetries, *cqlProtocolVersion, *windowFactor, 60, *cassandraSSL, *cassandraAuth, *cassandraHostVerification, *cassandraCreateKeyspace, *cassandraSchemaFile, nil)
if err != nil {
panic(fmt.Sprintf("Failed to initialize cassandra: %q", err))
}
Expand Down
5 changes: 4 additions & 1 deletion docker/docker-chaos/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ cassandra-retries = 0
cql-protocol-version = 4
# enable the creation of the mdata keyspace and tables, only one node needs this
cassandra-create-keyspace = false

# File containing the needed schemas in case database needs initializing
cassandra-schema-file = /etc/metrictank/schema-store-cassandra.toml
# enable SSL connection to cassandra
cassandra-ssl = false
# cassandra CA certficate path when using SSL
Expand Down Expand Up @@ -351,6 +352,8 @@ username = cassandra
password = cassandra
# enable the creation of the index keyspace and tables, only one node needs this
create-keyspace = false
# File containing the needed schemas in case database needs initializing
schema-file = /etc/metrictank/schema-idx-cassandra.toml

### in-memory only
[memory-idx]
Expand Down
5 changes: 4 additions & 1 deletion docker/docker-cluster/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ cassandra-retries = 0
cql-protocol-version = 4
# enable the creation of the mdata keyspace and tables, only one node needs this
cassandra-create-keyspace = false

# File containing the needed schemas in case database needs initializing
cassandra-schema-file = /etc/metrictank/schema-store-cassandra.toml
# enable SSL connection to cassandra
cassandra-ssl = false
# cassandra CA certficate path when using SSL
Expand Down Expand Up @@ -351,6 +352,8 @@ username = cassandra
password = cassandra
# enable the creation of the index keyspace and tables, only one node needs this
create-keyspace = false
# File containing the needed schemas in case database needs initializing
schema-file = /etc/metrictank/schema-idx-cassandra.toml

### in-memory only
[memory-idx]
Expand Down
5 changes: 4 additions & 1 deletion docker/docker-dev-custom-cfg-kafka/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ cassandra-retries = 0
cql-protocol-version = 4
# enable the creation of the mdata keyspace and tables, only one node needs this
cassandra-create-keyspace = true

# File containing the needed schemas in case database needs initializing
cassandra-schema-file = /etc/metrictank/schema-store-cassandra.toml
# enable SSL connection to cassandra
cassandra-ssl = false
# cassandra CA certficate path when using SSL
Expand Down Expand Up @@ -351,6 +352,8 @@ username = cassandra
password = cassandra
# enable the creation of the index keyspace and tables, only one node needs this
create-keyspace = true
# File containing the needed schemas in case database needs initializing
schema-file = /etc/metrictank/schema-idx-cassandra.toml

### in-memory only
[memory-idx]
Expand Down
7 changes: 7 additions & 0 deletions docker/docker-dev-scylla/datasources/graphite
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name":"graphite",
"type":"graphite",
"url":"http://graphite:80",
"access":"proxy",
"isDefault":false
}
7 changes: 7 additions & 0 deletions docker/docker-dev-scylla/datasources/metrictank
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name":"metrictank",
"type":"graphite",
"url":"http://metrictank:6060",
"access":"proxy",
"isDefault":true
}
55 changes: 55 additions & 0 deletions docker/docker-dev-scylla/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '2'

services:
metrictank:
hostname: metrictank
image: grafana/metrictank
ports:
- "6060:6060"
- "2003:2003"
volumes:
- ../../build/metrictank:/usr/bin/metrictank
- ../../scripts/config/metrictank-docker.ini:/etc/metrictank/metrictank.ini
- ../../scripts/config/storage-schemas.conf:/etc/metrictank/storage-schemas.conf
- ../../scripts/config/storage-aggregation.conf:/etc/metrictank/storage-aggregation.conf
- ../../scripts/config/schema-store-scylladb.toml:/etc/metrictank/schema-store-cassandra.toml
- ../../scripts/config/schema-idx-scylladb.toml:/etc/metrictank/schema-idx-cassandra.toml

environment:
WAIT_HOSTS: cassandra:9042
WAIT_TIMEOUT: 60
MT_HTTP_MULTI_TENANT: "false"
MT_MEMORY_IDX_TAG_SUPPORT: "true"
links:
- cassandra

cassandra:
hostname: cassandra
image: scylladb/scylla
ports:
- "9042:9042"

graphite:
hostname: graphite
image: raintank/graphite-mt
ports:
- "8080:80"
environment:
GRAPHITE_CLUSTER_SERVERS: metrictank:6060
GRAPHITE_STATSD_HOST: statsdaemon
WSGI_PROCESSES: 4
WSGI_THREADS: 25

grafana:
hostname: grafana
image: grafana/grafana
ports:
- "3000:3000"

statsdaemon:
hostname: statsdaemon
image: raintank/statsdaemon
ports:
- "8125:8125/udp"
volumes:
- "../statsdaemon.ini:/etc/statsdaemon.ini"
5 changes: 4 additions & 1 deletion docker/docker-dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ services:
- ../../scripts/config/metrictank-docker.ini:/etc/metrictank/metrictank.ini
- ../../scripts/config/storage-schemas.conf:/etc/metrictank/storage-schemas.conf
- ../../scripts/config/storage-aggregation.conf:/etc/metrictank/storage-aggregation.conf
- ../../scripts/config/schema-store-cassandra.toml:/etc/metrictank/schema-store-cassandra.toml
- ../../scripts/config/schema-idx-cassandra.toml:/etc/metrictank/schema-idx-cassandra.toml

environment:
WAIT_HOSTS: cassandra:9042
WAIT_TIMEOUT: 60
Expand Down Expand Up @@ -52,4 +55,4 @@ services:
ports:
- "8125:8125/udp"
volumes:
- "../statsdaemon.ini:/etc/statsdaemon.ini"
- "../statsdaemon.ini:/etc/statsdaemon.ini"
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ cassandra-retries = 0
cql-protocol-version = 4
# enable the creation of the mdata keyspace and tables, only one node needs this
cassandra-create-keyspace = true
# File containing the needed schemas in case database needs initializing
cassandra-schema-file = /etc/metrictank/schema-store-cassandra.toml
# enable SSL connection to cassandra
cassandra-ssl = false
# cassandra CA certficate path when using SSL
Expand Down Expand Up @@ -412,6 +414,8 @@ username = cassandra
password = cassandra
# enable the creation of the index keyspace and tables, only one node needs this
create-keyspace = true
# File containing the needed schemas in case database needs initializing
schema-file = /etc/metrictank/schema-idx-cassandra.toml
```

### in-memory only
Expand Down
10 changes: 10 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ cass config flags:
cql protocol version to use (default 4)
-prune-interval duration
Interval at which the index should be checked for stale series. (default 3h0m0s)
-schema-file string
File containing the needed schemas in case database needs initializing (default "/etc/metrictank/schema-idx-cassandra.toml")
-ssl
enable SSL connection to cassandra
-timeout duration
Expand Down Expand Up @@ -164,6 +166,8 @@ Flags:
number of partitions in cluster (default 1)
-partition-scheme string
method used for partitioning metrics. (byOrg|bySeries) (default "byOrg")
-schema-file string
File containing the needed schemas in case database needs initializing (default "/etc/metrictank/schema-idx-cassandra.toml")
-src-cass-addr string
Address of cassandra host to migrate from. (default "localhost")
-src-keyspace string
Expand Down Expand Up @@ -283,6 +287,8 @@ Flags:
password for authentication (default "cassandra")
-cassandra-retries int
how many times to retry a query before failing it
-cassandra-schema-file string
File containing the needed schemas in case database needs initializing (default "/etc/metrictank/schema-store-cassandra.toml")
-cassandra-ssl
enable SSL connection to cassandra
-cassandra-timeout int
Expand Down Expand Up @@ -345,6 +351,8 @@ Flags:
max number of outstanding reads before reads will be dropped. This is important if you run queries that result in many reads in parallel. (default 200000)
-cassandra-retries int
how many times to retry a query before failing it
-cassandra-schema-file string
File containing the needed schemas in case database needs initializing (default "/etc/metrictank/schema-store-cassandra.toml")
-cassandra-ssl
enable SSL connection to cassandra
-cassandra-timeout int
Expand Down Expand Up @@ -620,6 +628,8 @@ cass config flags:
cql protocol version to use (default 4)
-prune-interval duration
Interval at which the index should be checked for stale series. (default 3h0m0s)
-schema-file string
File containing the needed schemas in case database needs initializing (default "/etc/metrictank/schema-idx-cassandra.toml")
-ssl
enable SSL connection to cassandra
-timeout duration
Expand Down
27 changes: 9 additions & 18 deletions idx/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@ import (
"github.com/grafana/metrictank/idx"
"github.com/grafana/metrictank/idx/memory"
"github.com/grafana/metrictank/stats"
"github.com/grafana/metrictank/util"
"github.com/raintank/worldping-api/pkg/log"
"github.com/rakyll/globalconf"
"gopkg.in/raintank/schema.v1"
)

const KeyspaceSchema = `CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1} AND durable_writes = true`
const TableSchema = `CREATE TABLE IF NOT EXISTS %s.metric_idx (
id text,
orgid int,
partition int,
name text,
metric text,
interval int,
unit text,
mtype text,
tags set<text>,
lastupdate int,
PRIMARY KEY (partition, id)
) WITH compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}`

var (
// metric idx.cassadra.query-insert.ok is how many insert queries for a metric completed successfully (triggered by an add or an update)
statQueryInsertOk = stats.NewCounter32("idx.cassandra.query-insert.ok")
Expand Down Expand Up @@ -68,6 +53,7 @@ var (
auth bool
hostverification bool
createKeyspace bool
schemaFile string
keyspace string
hosts string
capath string
Expand Down Expand Up @@ -101,6 +87,7 @@ func ConfigSetup() *flag.FlagSet {
casIdx.DurationVar(&pruneInterval, "prune-interval", time.Hour*3, "Interval at which the index should be checked for stale series.")
casIdx.IntVar(&protoVer, "protocol-version", 4, "cql protocol version to use")
casIdx.BoolVar(&createKeyspace, "create-keyspace", true, "enable the creation of the index keyspace and tables, only one node needs this")
casIdx.StringVar(&schemaFile, "schema-file", "/etc/metrictank/schema-idx-cassandra.toml", "File containing the needed schemas in case database needs initializing")

casIdx.BoolVar(&ssl, "ssl", false, "enable SSL connection to cassandra")
casIdx.StringVar(&capath, "ca-path", "/etc/metrictank/ca.pem", "cassandra CA certficate path when using SSL")
Expand Down Expand Up @@ -173,13 +160,17 @@ func (c *CasIdx) InitBare() error {
return fmt.Errorf("failed to create cassandra session: %s", err)
}

// read templates
schemaKeyspace := util.ReadEntry(schemaFile, "schema_keyspace").(string)
schemaTable := util.ReadEntry(schemaFile, "schema_table").(string)

// create the keyspace or ensure it exists
if createKeyspace {
err = tmpSession.Query(fmt.Sprintf(KeyspaceSchema, keyspace)).Exec()
err = tmpSession.Query(fmt.Sprintf(schemaKeyspace, keyspace)).Exec()
if err != nil {
return fmt.Errorf("failed to initialize cassandra keyspace: %s", err)
}
err = tmpSession.Query(fmt.Sprintf(TableSchema, keyspace)).Exec()
err = tmpSession.Query(fmt.Sprintf(schemaTable, keyspace)).Exec()
if err != nil {
return fmt.Errorf("failed to initialize cassandra table: %s", err)
}
Expand Down
5 changes: 4 additions & 1 deletion metrictank-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ cassandra-retries = 0
cql-protocol-version = 4
# enable the creation of the mdata keyspace and tables, only one node needs this
cassandra-create-keyspace = true

# File containing the needed schemas in case database needs initializing
cassandra-schema-file = /etc/metrictank/schema-store-cassandra.toml
# enable SSL connection to cassandra
cassandra-ssl = false
# cassandra CA certficate path when using SSL
Expand Down Expand Up @@ -354,6 +355,8 @@ username = cassandra
password = cassandra
# enable the creation of the index keyspace and tables, only one node needs this
create-keyspace = true
# File containing the needed schemas in case database needs initializing
schema-file = /etc/metrictank/schema-idx-cassandra.toml

### in-memory only
[memory-idx]
Expand Down
Loading