Skip to content

Easy to use Cortex: Single binary, single process #1262

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 17 commits into from
May 16, 2019
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- checkout
- run:
name: Integration Test
command: MIGRATIONS_DIR=$(pwd)/pkg/configs/db/migrations make BUILD_IN_CONTAINER=false configs-integration-test
command: MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations make BUILD_IN_CONTAINER=false configs-integration-test

build:
<<: *defaults
Expand Down
11 changes: 1 addition & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
cmd/alertmanager/alertmanager
cmd/configs/configs
cmd/distributor/distributor
cmd/ingester/ingester
cmd/querier/querier
cmd/query-frontend/query-frontend
cmd/ruler/ruler
cmd/table-manager/table-manager
cmd/lite/lite
cmd/test-exporter/test-exporter
cmd/*/.migrations
cmd/cortex/cortex
.uptodate
.pkg
.cache
Expand Down
18 changes: 5 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ images:
PROTO_DEFS := $(shell find . $(DONT_FIND) -type f -name '*.proto' -print)
PROTO_GOS := $(patsubst %.proto,%.pb.go,$(PROTO_DEFS))

# Ensure a target for each image that needs a migration directory
MIGRATION_DIRS := cmd/alertmanager/.migrations cmd/configs/.migrations cmd/ruler/.migrations cmd/lite/.migrations

# Building binaries is now automated. The convention is to build a binary
# for every directory with main.go in it, in the ./cmd directory.
MAIN_GO := $(shell find . $(DONT_FIND) -type f -name 'main.go' -print)
Expand Down Expand Up @@ -86,7 +83,7 @@ NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \

ifeq ($(BUILD_IN_CONTAINER),true)

exes $(EXES) generated $(MIGRATION_DIRS) $(PROTO_GOS) lint test shell mod-check: build-image/$(UPTODATE)
exes $(EXES) generated $(PROTO_GOS) lint test shell mod-check: build-image/$(UPTODATE)
@mkdir -p $(shell pwd)/.pkg
@mkdir -p $(shell pwd)/.cache
$(SUDO) time docker run $(RM) $(TTY) -i \
Expand All @@ -103,10 +100,10 @@ configs-integration-test: build-image/$(UPTODATE)
-v $(shell pwd)/.cache:/go/cache \
-v $(shell pwd)/.pkg:/go/pkg \
-v $(shell pwd):/go/src/github.com/cortexproject/cortex \
-v $(shell pwd)/pkg/configs/db/migrations:/migrations \
-e MIGRATIONS_DIR=/migrations \
-v $(shell pwd)/cmd/cortex/migrations:/migrations \
--workdir /go/src/github.com/cortexproject/cortex \
--link "$$DB_CONTAINER":configs-db.cortex.local \
-e DB_ADDR=configs-db.cortex.local \
$(IMAGE_PREFIX)build-image $@; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \
Expand Down Expand Up @@ -139,7 +136,7 @@ shell:
bash

configs-integration-test:
/bin/bash -c "go test -tags 'netgo integration' -timeout 30s ./pkg/configs/... ./pkg/ruler/..."
/bin/bash -c "go test -v -tags 'netgo integration' -timeout 30s ./pkg/configs/... ./pkg/ruler/..."

mod-check:
GO111MODULE=on go mod download
Expand All @@ -148,15 +145,10 @@ mod-check:
GO111MODULE=on go mod vendor
@git diff --exit-code -- go.sum go.mod vendor/

%/.migrations:
# Ensure a each image that requires a migration dir has one in the build context
cp -r pkg/configs/db/migrations $@

endif

clean:
$(SUDO) docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true
rm -rf $(MIGRATION_DIRS)
rm -rf $(UPTODATE_FILES) $(EXES) $(PROTO_GOS) .cache
go clean ./...

Expand All @@ -175,7 +167,7 @@ load-images:
fi \
done

# Loads the built Docker images into the minikube environmen, and tags them with
# Loads the built Docker images into the minikube environment, and tags them with
# "latest" so the k8s manifests shipped with this code work.
prime-minikube: save-images
eval $$(minikube docker-env) ; \
Expand Down
11 changes: 0 additions & 11 deletions cmd/alertmanager/Dockerfile

This file was deleted.

61 changes: 0 additions & 61 deletions cmd/alertmanager/main.go

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/configs/Dockerfile

This file was deleted.

51 changes: 0 additions & 51 deletions cmd/configs/main.go

This file was deleted.

9 changes: 5 additions & 4 deletions cmd/lite/Dockerfile → cmd/cortex/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM alpine:3.8
RUN apk add --no-cache ca-certificates
COPY lite /bin/cortex
COPY .migrations /migrations/
COPY migrations /migrations/
COPY cortex /bin/cortex
COPY single-process-config.yaml /etc
EXPOSE 80
ENTRYPOINT [ "/bin/cortex" ]

ARG revision
LABEL org.opencontainers.image.title="lite" \
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/cmd/lite" \
LABEL org.opencontainers.image.title="cortex" \
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/cmd/cortex" \
org.opencontainers.image.revision="${revision}"
75 changes: 75 additions & 0 deletions cmd/cortex/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/tracing"
"gopkg.in/yaml.v2"

"github.com/cortexproject/cortex/pkg/cortex"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
)

func init() {
prometheus.MustRegister(version.NewCollector("cortex"))
}

func main() {
var (
cfg cortex.Config
configFile = ""
eventSampleRate int
)
flag.StringVar(&configFile, "config.file", "", "Configuration file to load.")
flag.IntVar(&eventSampleRate, "event.sample-rate", 0, "How often to sample observability events (0 = never).")

flagext.RegisterFlags(&cfg)
flag.Parse()

if configFile != "" {
if err := LoadConfig(configFile, &cfg); err != nil {
fmt.Printf("error loading config from %s: %v\n", configFile, err)
os.Exit(1)
}
}

// Parse a second time, as command line flags should take precedent over the config file.
flag.Parse()

util.InitLogger(&cfg.Server)
util.InitEvents(eventSampleRate)

// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace := tracing.NewFromEnv("cortex-" + cfg.Target.String())
defer trace.Close()

t, err := cortex.New(cfg)
util.CheckFatal("initializing cortex", err)

level.Info(util.Logger).Log("msg", "Starting Cortex", "version", version.Info())

if err := t.Run(); err != nil {
level.Error(util.Logger).Log("msg", "error running Cortex", "err", err)
}

err = t.Stop()
util.CheckFatal("initializing cortex", err)
}

// LoadConfig read YAML-formatted config from filename into cfg.
func LoadConfig(filename string, cfg interface{}) error {
buf, err := ioutil.ReadFile(filename)
if err != nil {
return errors.Wrap(err, "Error reading config file")
}

return yaml.UnmarshalStrict(buf, cfg)
}
65 changes: 65 additions & 0 deletions cmd/cortex/single-process-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

# Configuration for running Cortex in single-process mode.
# This should not be used in production. It is only for getting started
# and development.

# Disable the requirement that every request to Cortex has a
# X-Scope-OrgID header. `fake` will be substituted in instead.
auth_enabled: false

server:
http_listen_port: 9009

# Configure the server to allow messages up to 100MB.
grpc_server_max_recv_msg_size: 104857600
grpc_server_max_send_msg_size: 104857600
grpc_server_max_concurrent_streams: 1000

distributor:
shard_by_all_labels: true
pool:
health_check_ingesters: true

ingester_client:
grpc_client_config:
# Configure the client to allow messages up to 100MB.
max_recv_msg_size: 104857600
max_send_msg_size: 104857600
use_gzip_compression: true

ingester:
#chunk_idle_period: 15m

lifecycler:
address: 127.0.0.1

# We want to start immediately and flush on shutdown.
join_after: 0
claim_on_rollout: false
final_sleep: 0s
num_tokens: 512

# Use an in memory ring store, so we don't need to launch a Consul.
ring:
store: inmemory
replication_factor: 1

# Use local storage - BoltDB for the index, and the filesystem
# for the chunks.
schema:
configs:
- from: 2019-03-25
store: boltdb
object_store: filesystem
schema: v10
index:
prefix: index_
period: 168h

storage:
boltdb:
directory: /tmp/cortex/index

filesystem:
directory: /tmp/cortex/chunks

10 changes: 0 additions & 10 deletions cmd/distributor/Dockerfile

This file was deleted.

Loading