Skip to content

Adding the Ruler to the Single Binary #2854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* [ENHANCEMENT] Experimental TSDB: Added support to enforce max query time range length via `-store.max-query-length`. #2826
* [ENHANCEMENT] Ingester: Added new metric `cortex_ingester_flush_series_in_progress` that reports number of ongoing flush-series operations. Useful when calling `/flush` handler: if `cortex_ingester_flush_queue_length + cortex_ingester_flush_series_in_progress` is 0, all flushes are finished. #2778
* [ENHANCEMENT] Memberlist members can join cluster via SRV records. #2788
* [ENHANCEMENT] Added ruler to the single binary. #2854
* [BUGFIX] Fixed a bug in the index intersect code causing storage to return more chunks/series than required. #2796
* [BUGFIX] Fixed the number of reported keys in the background cache queue. #2764
* [BUGFIX] Fix race in processing of headers in sharded queries. #2762
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!cortex-rules
!cortex-tsdb
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ tsdb:

storage:
engine: tsdb

ruler:
enable_api: true
enable_sharding: true
poll_interval: 2s
storage:
type: s3
s3:
bucketnames: cortex-rules
s3forcepathstyle: true
s3: http://cortex:supersecret@minio.:9000
ring:
kvstore:
store: consul
consul:
host: consul:8500
8 changes: 7 additions & 1 deletion docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ ruler_client:
[poll_interval: <duration> | default = 1m]

storage:
# Method to use for backend rule storage (configdb, azure, gcs, s3)
# Method to use for backend rule storage (configdb, azure, gcs, s3, swift,
# local)
# CLI flag: -ruler.storage.type
[type: <string> | default = "configdb"]

Expand Down Expand Up @@ -958,6 +959,11 @@ storage:
# CLI flag: -ruler.storage.swift.container-name
[container_name: <string> | default = "cortex"]

local:
# Directory to scan for rules
# CLI flag: -ruler.storage.local.directory
[directory: <string> | default = ""]

# file path to store temporary rule files for the prometheus rule managers
# CLI flag: -ruler.rule-path
[rule_path: <string> | default = "/rules"]
Expand Down
14 changes: 13 additions & 1 deletion docs/configuration/single-process-config-blocks-gossip-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ tsdb:
dir: /tmp/cortex/storage

frontend_worker:
match_max_concurrent: true
match_max_concurrent: true

ruler:
enable_api: true
enable_sharding: true
poll_interval: 2s
storage:
type: local
local:
directory: /tmp/cortex/rules
ring:
kvstore:
store: memberlist
14 changes: 13 additions & 1 deletion docs/configuration/single-process-config-blocks-gossip-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ tsdb:
dir: /tmp/cortex/storage

frontend_worker:
match_max_concurrent: true
match_max_concurrent: true

ruler:
enable_api: true
enable_sharding: true
poll_interval: 2s
storage:
type: local
local:
directory: /tmp/cortex/rules
ring:
kvstore:
store: memberlist
9 changes: 9 additions & 0 deletions docs/configuration/single-process-config-blocks-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,12 @@ frontend_worker:
tls_cert_path: "client.crt"
tls_key_path: "client.key"
tls_ca_path: "root.crt"

ruler:
enable_api: true
enable_sharding: false
poll_interval: 2s
storage:
type: local
local:
directory: /tmp/cortex/rules
11 changes: 10 additions & 1 deletion docs/configuration/single-process-config-blocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,13 @@ compactor:
store: inmemory

frontend_worker:
match_max_concurrent: true
match_max_concurrent: true

ruler:
enable_api: true
enable_sharding: false
poll_interval: 2s
storage:
type: local
local:
directory: /tmp/cortex/rules
11 changes: 10 additions & 1 deletion docs/configuration/single-process-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ purger:
object_store_type: filesystem

frontend_worker:
match_max_concurrent: true
match_max_concurrent: true

ruler:
enable_api: true
enable_sharding: false
poll_interval: 2s
storage:
type: local
local:
directory: /tmp/cortex/rules
37 changes: 37 additions & 0 deletions integration/api_ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package main

import (
"path"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -94,3 +96,38 @@ func TestRulerAPI(t *testing.T) {
// Ensure no service-specific metrics prefix is used by the wrong service.
assertServiceMetricsPrefixes(t, Ruler, ruler)
}

func TestRulerAPISingleBinary(t *testing.T) {
s, err := e2e.NewScenario(networkName)
require.NoError(t, err)
defer s.Close()

namespace := "ns"
user := "fake"

configOverrides := map[string]string{
"-ruler.storage.local.directory": filepath.Join(e2e.ContainerSharedDir, "ruler_configs"),
}

// Start Cortex components.
require.NoError(t, copyFileToSharedDir(s, "docs/configuration/single-process-config.yaml", cortexConfigFile))
require.NoError(t, writeFileToSharedDir(s, path.Join("ruler_configs", user, namespace), []byte(cortexRulerUserConfigYaml)))
cortex := e2ecortex.NewSingleBinaryWithConfigFile("cortex", cortexConfigFile, configOverrides, "", 9009, 9095)
require.NoError(t, s.StartAndWaitReady(cortex))

// Create a client with the ruler address configured
c, err := e2ecortex.NewClient("", "", "", cortex.HTTPEndpoint(), "")
require.NoError(t, err)

// Wait until the user manager is created
require.NoError(t, cortex.WaitSumMetrics(e2e.Equals(1), "cortex_ruler_managers_total"))

// Check to ensure the rules running in the cortex match what was set
rgs, err := c.GetRuleGroups()
require.NoError(t, err)

retrievedNamespace, exists := rgs[namespace]
require.True(t, exists)
require.Len(t, retrievedNamespace, 1)
require.Equal(t, retrievedNamespace[0].Name, "rule")
}
12 changes: 12 additions & 0 deletions integration/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ const (
receivers:
- name: "example_receiver"
`

cortexRulerUserConfigYaml = `groups:
- name: rule
interval: 100s
rules:
- record: test_rule
alert: ""
expr: up
for: 0s
labels: {}
annotations: {}
`
)

var (
Expand Down
3 changes: 3 additions & 0 deletions integration/e2ecortex/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ func NewSingleBinary(name string, flags map[string]string, image string, otherPo
"-ingester.concurrent-flushes": "10",
"-ingester.max-transfer-retries": "10",
"-ingester.num-tokens": "512",
// Ruler
"-ruler.storage.type": "local",
"-ruler.storage.local.directory": "/tmp/cortex/rules",
}, flags))...),
e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299),
httpPort,
Expand Down
8 changes: 5 additions & 3 deletions pkg/cortex/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"google.golang.org/grpc/health/grpc_health_v1"
"gopkg.in/yaml.v2"

"github.com/prometheus/prometheus/promql"
prom_storage "github.com/prometheus/prometheus/storage"

"github.com/cortexproject/cortex/pkg/alertmanager"
"github.com/cortexproject/cortex/pkg/api"
"github.com/cortexproject/cortex/pkg/chunk"
Expand Down Expand Up @@ -219,9 +222,8 @@ type Cortex struct {
StoreGateway *storegateway.StoreGateway
MemberlistKV *memberlist.KVInitService

// Queryables that the querier should use to query the long
// term storage. It depends on the storage engine used.
StoreQueryables []querier.QueryableWithFilter
Queryable prom_storage.SampleAndChunkQueryable
Engine *promql.Engine
}

// New makes a new Cortex.
Expand Down
17 changes: 17 additions & 0 deletions pkg/cortex/cortex_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package cortex

import (
"net/url"
"testing"

"github.com/stretchr/testify/require"

"github.com/cortexproject/cortex/pkg/chunk/aws"
"github.com/cortexproject/cortex/pkg/chunk/storage"
"github.com/cortexproject/cortex/pkg/ingester"
"github.com/cortexproject/cortex/pkg/ring"
"github.com/cortexproject/cortex/pkg/ring/kv"
"github.com/cortexproject/cortex/pkg/ruler"
"github.com/cortexproject/cortex/pkg/storage/backend/s3"
"github.com/cortexproject/cortex/pkg/storage/tsdb"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/cortexproject/cortex/pkg/util/services"
)

func TestCortex(t *testing.T) {
rulerURL, err := url.Parse("inmemory:///rules")
require.NoError(t, err)

cfg := Config{
Storage: storage.Config{
Engine: storage.StorageEngineTSDB, // makes config easier
Expand Down Expand Up @@ -47,6 +54,16 @@ func TestCortex(t *testing.T) {
},
},
},
Ruler: ruler.Config{
StoreConfig: ruler.RuleStoreConfig{
Type: "s3",
S3: aws.S3Config{
S3: flagext.URLValue{
URL: rulerURL,
},
},
},
},
Target: All,
}

Expand Down
Loading