Skip to content

Commit

Permalink
Introduce continuous test tool (#1535)
Browse files Browse the repository at this point in the history
* Added skeleton for mimir-continuous-test tool

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Added metrics server and init logger

Signed-off-by: Marco Pracucci <marco@pracucci.com>
  • Loading branch information
pracucci committed Mar 23, 2022
1 parent 6ebead2 commit edb092b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmd/test-exporter/test-exporter
cmd/mimir/mimir
cmd/query-tee/query-tee
cmd/metaconvert/metaconvert
cmd/mimir-continuous-test/mimir-continuous-test
.uptodate
.pkg
.cache
Expand All @@ -19,6 +20,7 @@ jsonnet-tests/
/mimirtool
/query-tee
/test-exporter
/mimir-continuous-test

# This is custom Makefile modification, if it exists.
Makefile.local
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ dist: ## Generates binaries for a Mimir release.
echo "Building metaconvert for $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build $(GO_FLAGS) -o ./dist/metaconvert-$$os-$$arch$$suffix ./cmd/metaconvert; \
sha256sum ./dist/metaconvert-$$os-$$arch$$suffix | cut -d ' ' -f 1 > ./dist/metaconvert-$$os-$$arch$$suffix-sha-256; \
echo "Building mimir-continuous-test for $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build $(GO_FLAGS) -o ./dist/mimir-continuous-test-$$os-$$arch$$suffix ./cmd/mimir-continuous-test; \
sha256sum ./dist/mimir-continuous-test-$$os-$$arch$$suffix | cut -d ' ' -f 1 > ./dist/mimir-continuous-test-$$os-$$arch$$suffix-sha-256; \
done; \
done; \
touch $@
Expand Down
11 changes: 11 additions & 0 deletions cmd/mimir-continuous-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: AGPL-3.0-only

FROM alpine:3.15.0
RUN apk add --no-cache ca-certificates
COPY mimir-continuous-test /
ENTRYPOINT ["/mimir-continuous-test"]

ARG revision
LABEL org.opencontainers.image.title="mimir-continuous-test" \
org.opencontainers.image.source="https://github.com/grafana/mimir/tree/main/cmd/mimir-continuous-test" \
org.opencontainers.image.revision="${revision}"
49 changes: 49 additions & 0 deletions cmd/mimir-continuous-test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: AGPL-3.0-only

package main

import (
"flag"
"os"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/weaveworks/common/logging"
"github.com/weaveworks/common/server"

"github.com/grafana/mimir/pkg/util/instrumentation"
util_log "github.com/grafana/mimir/pkg/util/log"
)

type Config struct {
ServerMetricsPort int
LogLevel logging.Level
}

func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.IntVar(&cfg.ServerMetricsPort, "server.metrics-port", 9900, "The port where metrics are exposed.")
cfg.LogLevel.RegisterFlags(f)
}

func main() {
// Parse CLI flags.
cfg := &Config{}
cfg.RegisterFlags(flag.CommandLine)
flag.Parse()

util_log.InitLogger(&server.Config{
LogLevel: cfg.LogLevel,
})
logger := util_log.Logger

// Run the instrumentation server.
registry := prometheus.NewRegistry()
registry.MustRegister(collectors.NewGoCollector())

i := instrumentation.NewMetricsServer(cfg.ServerMetricsPort, registry)
if err := i.Start(); err != nil {
level.Error(logger).Log("msg", "Unable to start instrumentation server", "err", err.Error())
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion cmd/query-tee/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ ENTRYPOINT ["/query-tee"]

ARG revision
LABEL org.opencontainers.image.title="query-tee" \
org.opencontainers.image.source="https://github.com/grafana/mimir/tree/main/tools/query-tee" \
org.opencontainers.image.source="https://github.com/grafana/mimir/tree/main/cmd/query-tee" \
org.opencontainers.image.revision="${revision}"
3 changes: 2 additions & 1 deletion cmd/query-tee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/weaveworks/common/logging"
"github.com/weaveworks/common/server"

"github.com/grafana/mimir/pkg/util/instrumentation"
util_log "github.com/grafana/mimir/pkg/util/log"
"github.com/grafana/mimir/tools/querytee"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func main() {
registry := prometheus.NewRegistry()
registry.MustRegister(collectors.NewGoCollector())

i := querytee.NewInstrumentationServer(cfg.ServerMetricsPort, registry)
i := instrumentation.NewMetricsServer(cfg.ServerMetricsPort, registry)
if err := i.Start(); err != nil {
level.Error(util_log.Logger).Log("msg", "Unable to start instrumentation server", "err", err.Error())
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.

package querytee
package instrumentation

import (
"fmt"
Expand All @@ -18,22 +18,22 @@ import (
util_log "github.com/grafana/mimir/pkg/util/log"
)

type InstrumentationServer struct {
type MetricsServer struct {
port int
registry *prometheus.Registry
srv *http.Server
}

// NewInstrumentationServer returns a server exposing Prometheus metrics.
func NewInstrumentationServer(port int, registry *prometheus.Registry) *InstrumentationServer {
return &InstrumentationServer{
// NewMetricsServer returns a server exposing Prometheus metrics.
func NewMetricsServer(port int, registry *prometheus.Registry) *MetricsServer {
return &MetricsServer{
port: port,
registry: registry,
}
}

// Start the instrumentation server.
func (s *InstrumentationServer) Start() error {
func (s *MetricsServer) Start() error {
// Setup listener first, so we can fail early if the port is in use.
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", s.port))
if err != nil {
Expand All @@ -57,7 +57,7 @@ func (s *InstrumentationServer) Start() error {
}

// Stop closes the instrumentation server.
func (s *InstrumentationServer) Stop() {
func (s *MetricsServer) Stop() {
if s.srv != nil {
s.srv.Close()
s.srv = nil
Expand Down

0 comments on commit edb092b

Please sign in to comment.