Skip to content

Commit 4bf1dcf

Browse files
authored
Merge pull request #1262 from grafana/single-binary
Easy to use Cortex: Single binary, single process
2 parents 3afa323 + ccd9362 commit 4bf1dcf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1506
-1353
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- checkout
5757
- run:
5858
name: Integration Test
59-
command: MIGRATIONS_DIR=$(pwd)/pkg/configs/db/migrations make BUILD_IN_CONTAINER=false configs-integration-test
59+
command: MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations make BUILD_IN_CONTAINER=false configs-integration-test
6060

6161
build:
6262
<<: *defaults

.gitignore

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
cmd/alertmanager/alertmanager
2-
cmd/configs/configs
3-
cmd/distributor/distributor
4-
cmd/ingester/ingester
5-
cmd/querier/querier
6-
cmd/query-frontend/query-frontend
7-
cmd/ruler/ruler
8-
cmd/table-manager/table-manager
9-
cmd/lite/lite
101
cmd/test-exporter/test-exporter
11-
cmd/*/.migrations
2+
cmd/cortex/cortex
123
.uptodate
134
.pkg
145
.cache

Makefile

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ images:
3434
PROTO_DEFS := $(shell find . $(DONT_FIND) -type f -name '*.proto' -print)
3535
PROTO_GOS := $(patsubst %.proto,%.pb.go,$(PROTO_DEFS))
3636

37-
# Ensure a target for each image that needs a migration directory
38-
MIGRATION_DIRS := cmd/alertmanager/.migrations cmd/configs/.migrations cmd/ruler/.migrations cmd/lite/.migrations
39-
4037
# Building binaries is now automated. The convention is to build a binary
4138
# for every directory with main.go in it, in the ./cmd directory.
4239
MAIN_GO := $(shell find . $(DONT_FIND) -type f -name 'main.go' -print)
@@ -86,7 +83,7 @@ NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \
8683

8784
ifeq ($(BUILD_IN_CONTAINER),true)
8885

89-
exes $(EXES) generated $(MIGRATION_DIRS) $(PROTO_GOS) lint test shell mod-check: build-image/$(UPTODATE)
86+
exes $(EXES) generated $(PROTO_GOS) lint test shell mod-check: build-image/$(UPTODATE)
9087
@mkdir -p $(shell pwd)/.pkg
9188
@mkdir -p $(shell pwd)/.cache
9289
$(SUDO) time docker run $(RM) $(TTY) -i \
@@ -103,10 +100,10 @@ configs-integration-test: build-image/$(UPTODATE)
103100
-v $(shell pwd)/.cache:/go/cache \
104101
-v $(shell pwd)/.pkg:/go/pkg \
105102
-v $(shell pwd):/go/src/github.com/cortexproject/cortex \
106-
-v $(shell pwd)/pkg/configs/db/migrations:/migrations \
107-
-e MIGRATIONS_DIR=/migrations \
103+
-v $(shell pwd)/cmd/cortex/migrations:/migrations \
108104
--workdir /go/src/github.com/cortexproject/cortex \
109105
--link "$$DB_CONTAINER":configs-db.cortex.local \
106+
-e DB_ADDR=configs-db.cortex.local \
110107
$(IMAGE_PREFIX)build-image $@; \
111108
status=$$?; \
112109
test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \
@@ -139,7 +136,7 @@ shell:
139136
bash
140137

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

144141
mod-check:
145142
GO111MODULE=on go mod download
@@ -148,15 +145,10 @@ mod-check:
148145
GO111MODULE=on go mod vendor
149146
@git diff --exit-code -- go.sum go.mod vendor/
150147

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

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

@@ -175,7 +167,7 @@ load-images:
175167
fi \
176168
done
177169

178-
# Loads the built Docker images into the minikube environmen, and tags them with
170+
# Loads the built Docker images into the minikube environment, and tags them with
179171
# "latest" so the k8s manifests shipped with this code work.
180172
prime-minikube: save-images
181173
eval $$(minikube docker-env) ; \

cmd/alertmanager/Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

cmd/alertmanager/main.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

cmd/configs/Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

cmd/configs/main.go

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
FROM alpine:3.8
22
RUN apk add --no-cache ca-certificates
3-
COPY lite /bin/cortex
4-
COPY .migrations /migrations/
3+
COPY migrations /migrations/
4+
COPY cortex /bin/cortex
5+
COPY single-process-config.yaml /etc
56
EXPOSE 80
67
ENTRYPOINT [ "/bin/cortex" ]
78

89
ARG revision
9-
LABEL org.opencontainers.image.title="lite" \
10-
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/cmd/lite" \
10+
LABEL org.opencontainers.image.title="cortex" \
11+
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/cmd/cortex" \
1112
org.opencontainers.image.revision="${revision}"

cmd/cortex/main.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
9+
"github.com/go-kit/kit/log/level"
10+
"github.com/pkg/errors"
11+
"github.com/prometheus/client_golang/prometheus"
12+
"github.com/prometheus/common/version"
13+
"github.com/weaveworks/common/tracing"
14+
"gopkg.in/yaml.v2"
15+
16+
"github.com/cortexproject/cortex/pkg/cortex"
17+
"github.com/cortexproject/cortex/pkg/util"
18+
"github.com/cortexproject/cortex/pkg/util/flagext"
19+
)
20+
21+
func init() {
22+
prometheus.MustRegister(version.NewCollector("cortex"))
23+
}
24+
25+
func main() {
26+
var (
27+
cfg cortex.Config
28+
configFile = ""
29+
eventSampleRate int
30+
)
31+
flag.StringVar(&configFile, "config.file", "", "Configuration file to load.")
32+
flag.IntVar(&eventSampleRate, "event.sample-rate", 0, "How often to sample observability events (0 = never).")
33+
34+
flagext.RegisterFlags(&cfg)
35+
flag.Parse()
36+
37+
if configFile != "" {
38+
if err := LoadConfig(configFile, &cfg); err != nil {
39+
fmt.Printf("error loading config from %s: %v\n", configFile, err)
40+
os.Exit(1)
41+
}
42+
}
43+
44+
// Parse a second time, as command line flags should take precedent over the config file.
45+
flag.Parse()
46+
47+
util.InitLogger(&cfg.Server)
48+
util.InitEvents(eventSampleRate)
49+
50+
// Setting the environment variable JAEGER_AGENT_HOST enables tracing
51+
trace := tracing.NewFromEnv("cortex-" + cfg.Target.String())
52+
defer trace.Close()
53+
54+
t, err := cortex.New(cfg)
55+
util.CheckFatal("initializing cortex", err)
56+
57+
level.Info(util.Logger).Log("msg", "Starting Cortex", "version", version.Info())
58+
59+
if err := t.Run(); err != nil {
60+
level.Error(util.Logger).Log("msg", "error running Cortex", "err", err)
61+
}
62+
63+
err = t.Stop()
64+
util.CheckFatal("initializing cortex", err)
65+
}
66+
67+
// LoadConfig read YAML-formatted config from filename into cfg.
68+
func LoadConfig(filename string, cfg interface{}) error {
69+
buf, err := ioutil.ReadFile(filename)
70+
if err != nil {
71+
return errors.Wrap(err, "Error reading config file")
72+
}
73+
74+
return yaml.UnmarshalStrict(buf, cfg)
75+
}
File renamed without changes.

0 commit comments

Comments
 (0)