Skip to content

Commit 713f201

Browse files
authored
Replace weaveworks common with dskit (grafana#5274)
1 parent d59717e commit 713f201

File tree

31 files changed

+207
-129
lines changed

31 files changed

+207
-129
lines changed

.github/depcheck.yml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ go_modules:
1010
- github.com/prometheus/memcached_exporter
1111
- github.com/prometheus/node_exporter
1212
- github.com/prometheus/statsd_exporter
13-
- github.com/weaveworks/common
1413
- go.opentelemetry.io/collector
1514
- sigs.k8s.io/controller-runtime
1615

cmd/grafana-agent/entrypoint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/grafana/agent/pkg/supportbundle"
2626
"github.com/grafana/agent/pkg/traces"
2727
"github.com/grafana/agent/pkg/usagestats"
28+
"github.com/grafana/dskit/signals"
2829
"github.com/oklog/run"
2930
"github.com/prometheus/client_golang/prometheus"
30-
"github.com/weaveworks/common/signals"
3131
"google.golang.org/grpc"
3232
"gopkg.in/yaml.v2"
3333
)
@@ -395,7 +395,7 @@ func (ep *Entrypoint) Start() error {
395395

396396
// Create a signal handler that will stop the Entrypoint once a termination
397397
// signal is received.
398-
signalHandler := signals.NewHandler(server.GoKitLogger(ep.log))
398+
signalHandler := signals.NewHandler(ep.log)
399399

400400
notifier := make(chan os.Signal, 1)
401401
signal.Notify(notifier, syscall.SIGHUP)

component/common/net/config.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Package http contains a River serializable definition of the weaveworks weaveworks config in
2-
// https://github.com/weaveworks/common/blob/master/server/server.go#L62.
1+
// Package http contains a River serializable definition of the dskit config in
2+
// https://github.com/grafana/dskit/blob/main/server/server.go#L72.
33
package net
44

55
import (
66
"flag"
77
"math"
88
"time"
99

10-
weaveworks "github.com/weaveworks/common/server"
10+
dskit "github.com/grafana/dskit/server"
1111
)
1212

1313
const (
@@ -16,27 +16,27 @@ const (
1616
// using zero as default grpc port to assing random free port when not configured
1717
DefaultGRPCPort = 0
1818

19-
// defaults inherited from weaveworks
19+
// defaults inherited from dskit
2020
durationInfinity = time.Duration(math.MaxInt64)
2121
size4MB = 4 << 20
2222
)
2323

24-
// ServerConfig is a River configuration that allows one to configure a weaveworks.Server. It
24+
// ServerConfig is a River configuration that allows one to configure a dskit.Server. It
2525
// exposes a subset of the available configurations.
2626
type ServerConfig struct {
27-
// HTTP configures the HTTP weaveworks. Note that despite the block being present or not,
28-
// the weaveworks is always started.
27+
// HTTP configures the HTTP dskit. Note that despite the block being present or not,
28+
// the dskit is always started.
2929
HTTP *HTTPConfig `river:"http,block,optional"`
3030

31-
// GRPC configures the gRPC weaveworks. Note that despite the block being present or not,
32-
// the weaveworks is always started.
31+
// GRPC configures the gRPC dskit. Note that despite the block being present or not,
32+
// the dskit is always started.
3333
GRPC *GRPCConfig `river:"grpc,block,optional"`
3434

3535
// GracefulShutdownTimeout configures a timeout to gracefully shut down the server.
3636
GracefulShutdownTimeout time.Duration `river:"graceful_shutdown_timeout,attr,optional"`
3737
}
3838

39-
// HTTPConfig configures the HTTP weaveworks started by weaveworks.Server.
39+
// HTTPConfig configures the HTTP dskit started by dskit.Server.
4040
type HTTPConfig struct {
4141
ListenAddress string `river:"listen_address,attr,optional"`
4242
ListenPort int `river:"listen_port,attr,optional"`
@@ -46,8 +46,8 @@ type HTTPConfig struct {
4646
ServerIdleTimeout time.Duration `river:"server_idle_timeout,attr,optional"`
4747
}
4848

49-
// Into applies the configs from HTTPConfig into a weaveworks.Into.
50-
func (h *HTTPConfig) Into(c *weaveworks.Config) {
49+
// Into applies the configs from HTTPConfig into a dskit.Into.
50+
func (h *HTTPConfig) Into(c *dskit.Config) {
5151
c.HTTPListenAddress = h.ListenAddress
5252
c.HTTPListenPort = h.ListenPort
5353
c.HTTPConnLimit = h.ConnLimit
@@ -56,7 +56,7 @@ func (h *HTTPConfig) Into(c *weaveworks.Config) {
5656
c.HTTPServerIdleTimeout = h.ServerIdleTimeout
5757
}
5858

59-
// GRPCConfig configures the gRPC weaveworks started by weaveworks.Server.
59+
// GRPCConfig configures the gRPC dskit started by dskit.Server.
6060
type GRPCConfig struct {
6161
ListenAddress string `river:"listen_address,attr,optional"`
6262
ListenPort int `river:"listen_port,attr,optional"`
@@ -69,8 +69,8 @@ type GRPCConfig struct {
6969
ServerMaxConcurrentStreams uint `river:"server_max_concurrent_streams,attr,optional"`
7070
}
7171

72-
// Into applies the configs from GRPCConfig into a weaveworks.Into.
73-
func (g *GRPCConfig) Into(c *weaveworks.Config) {
72+
// Into applies the configs from GRPCConfig into a dskit.Into.
73+
func (g *GRPCConfig) Into(c *dskit.Config) {
7474
c.GRPCListenAddress = g.ListenAddress
7575
c.GRPCListenPort = g.ListenPort
7676
c.GRPCConnLimit = g.ConnLimit
@@ -82,11 +82,11 @@ func (g *GRPCConfig) Into(c *weaveworks.Config) {
8282
c.GPRCServerMaxConcurrentStreams = g.ServerMaxConcurrentStreams
8383
}
8484

85-
// Convert converts the River-based ServerConfig into a weaveworks.Config object.
86-
func (c *ServerConfig) convert() weaveworks.Config {
87-
cfg := newWeaveworksDefaultConfig()
85+
// Convert converts the River-based ServerConfig into a dskit.Config object.
86+
func (c *ServerConfig) convert() dskit.Config {
87+
cfg := newdskitDefaultConfig()
8888
// use the configured http/grpc blocks, and if not, use a mixin of our defaults, and
89-
// weaveworks's as a fallback
89+
// dskit's as a fallback
9090
if c.HTTP != nil {
9191
c.HTTP.Into(&cfg)
9292
} else {
@@ -101,9 +101,9 @@ func (c *ServerConfig) convert() weaveworks.Config {
101101
return cfg
102102
}
103103

104-
// newWeaveworksDefaultConfig creates a new weaveworks.Config object with some overridden defaults.
105-
func newWeaveworksDefaultConfig() weaveworks.Config {
106-
c := weaveworks.Config{}
104+
// newdskitDefaultConfig creates a new dskit.Config object with some overridden defaults.
105+
func newdskitDefaultConfig() dskit.Config {
106+
c := dskit.Config{}
107107
c.RegisterFlags(flag.NewFlagSet("empty", flag.ContinueOnError))
108108
// By default, do not register instrumentation since every metric is later registered
109109
// inside a custom register
@@ -112,7 +112,7 @@ func newWeaveworksDefaultConfig() weaveworks.Config {
112112
}
113113

114114
// DefaultServerConfig creates a new ServerConfig with defaults applied. Note that some are inherited from
115-
// weaveworks, but copied in our config model to make the mixin logic simpler.
115+
// dskit, but copied in our config model to make the mixin logic simpler.
116116
func DefaultServerConfig() *ServerConfig {
117117
return &ServerConfig{
118118
HTTP: &HTTPConfig{

component/common/net/config_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"testing"
55
"time"
66

7+
dskit "github.com/grafana/dskit/server"
78
"github.com/stretchr/testify/require"
8-
weaveworks "github.com/weaveworks/common/server"
99

1010
"github.com/grafana/river"
1111
)
@@ -34,16 +34,16 @@ func TestConfig(t *testing.T) {
3434
type testcase struct {
3535
raw string
3636
errExpected bool
37-
assert func(t *testing.T, config weaveworks.Config)
37+
assert func(t *testing.T, config dskit.Config)
3838
}
3939
var cases = map[string]testcase{
4040
"empty config applies defaults": {
4141
raw: ``,
42-
assert: func(t *testing.T, config weaveworks.Config) {
42+
assert: func(t *testing.T, config dskit.Config) {
4343
// custom defaults
4444
require.Equal(t, DefaultHTTPPort, config.HTTPListenPort)
4545
require.Equal(t, DefaultGRPCPort, config.GRPCListenPort)
46-
// defaults inherited from weaveworks
46+
// defaults inherited from dskit
4747
require.Equal(t, "", config.HTTPListenAddress)
4848
require.Equal(t, "", config.GRPCListenAddress)
4949
require.False(t, config.RegisterInstrumentation)
@@ -62,7 +62,7 @@ func TestConfig(t *testing.T) {
6262
conn_limit = 10
6363
server_write_timeout = "10s"
6464
}`,
65-
assert: func(t *testing.T, config weaveworks.Config) {
65+
assert: func(t *testing.T, config dskit.Config) {
6666
require.Equal(t, 8080, config.HTTPListenPort)
6767
require.Equal(t, "0.0.0.0", config.HTTPListenAddress)
6868
require.Equal(t, 10, config.HTTPConnLimit)
@@ -84,7 +84,7 @@ func TestConfig(t *testing.T) {
8484
listen_address = "0.0.0.0"
8585
server_max_send_msg_size = 10
8686
}`,
87-
assert: func(t *testing.T, config weaveworks.Config) {
87+
assert: func(t *testing.T, config dskit.Config) {
8888
// these should be overridden
8989
require.Equal(t, 8080, config.HTTPListenPort)
9090
require.Equal(t, "0.0.0.0", config.HTTPListenAddress)
@@ -125,7 +125,7 @@ func TestConfig(t *testing.T) {
125125
server_max_send_msg_size = 6
126126
server_max_concurrent_streams = 7
127127
}`,
128-
assert: func(t *testing.T, config weaveworks.Config) {
128+
assert: func(t *testing.T, config dskit.Config) {
129129
// general
130130
require.Equal(t, time.Minute, config.ServerGracefulShutdownTimeout)
131131
// http

component/common/net/server.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import (
66
"github.com/go-kit/log"
77
"github.com/go-kit/log/level"
88
"github.com/gorilla/mux"
9+
dskit "github.com/grafana/dskit/server"
910
"github.com/prometheus/client_golang/prometheus"
1011
"github.com/prometheus/common/model"
11-
"github.com/weaveworks/common/logging"
12-
weaveworks "github.com/weaveworks/common/server"
1312
)
1413

15-
// TargetServer is wrapper around weaveworks.Server that handles some common configuration used in all flow components
14+
// TargetServer is wrapper around dskit.Server that handles some common configuration used in all flow components
1615
// that expose a network server. It just handles configuration and initialization, the handlers implementation are left
1716
// to the consumer.
1817
type TargetServer struct {
1918
logger log.Logger
20-
config *weaveworks.Config
19+
config *dskit.Config
2120
metricsNamespace string
22-
server *weaveworks.Server
21+
server *dskit.Server
2322
}
2423

2524
// NewTargetServer creates a new TargetServer, applying some defaults to the server configuration.
@@ -38,7 +37,7 @@ func NewTargetServer(logger log.Logger, metricsNamespace string, reg prometheus.
3837
config = DefaultServerConfig()
3938
}
4039

41-
// convert from River into the weaveworks config
40+
// convert from River into the dskit config
4241
serverCfg := config.convert()
4342
// Set the config to the new combined config.
4443
// Avoid logging entire received request on failures
@@ -50,19 +49,19 @@ func NewTargetServer(logger log.Logger, metricsNamespace string, reg prometheus.
5049
// To prevent metric collisions because all metrics are going to be registered in the global Prometheus registry.
5150
ts.config.MetricsNamespace = ts.metricsNamespace
5251
// We don't want the /debug and /metrics endpoints running, since this is not the main Flow HTTP server.
53-
// We want this target to expose the least surface area possible, hence disabling WeaveWorks HTTP server metrics
52+
// We want this target to expose the least surface area possible, hence disabling dskit HTTP server metrics
5453
// and debugging functionality.
5554
ts.config.RegisterInstrumentation = false
56-
// Add logger to weaveworks
57-
ts.config.Log = logging.GoKit(ts.logger)
55+
// Add logger to dskit
56+
ts.config.Log = ts.logger
5857

5958
return ts, nil
6059
}
6160

6261
// MountAndRun mounts the handlers and starting the server.
6362
func (ts *TargetServer) MountAndRun(mountRoute func(router *mux.Router)) error {
6463
level.Info(ts.logger).Log("msg", "starting server")
65-
srv, err := weaveworks.New(*ts.config)
64+
srv, err := dskit.New(*ts.config)
6665
if err != nil {
6766
return err
6867
}

component/loki/process/stages/drop_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
"github.com/alecthomas/units"
1313
"github.com/grafana/agent/pkg/util"
14+
dskit "github.com/grafana/dskit/server"
1415
"github.com/prometheus/client_golang/prometheus"
1516
"github.com/prometheus/common/model"
1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
18-
ww "github.com/weaveworks/common/server"
1919
)
2020

2121
// Not all these are tested but are here to make sure the different types marshal without error
@@ -47,7 +47,7 @@ stage.drop {
4747

4848
func TestDropStage(t *testing.T) {
4949
// Enable debug logging
50-
cfg := &ww.Config{}
50+
cfg := &dskit.Config{}
5151
require.Nil(t, cfg.LogLevel.Set("debug"))
5252

5353
tenBytes, _ := units.ParseBase2Bytes("10B")

component/loki/source/gcplog/internal/gcplogtarget/push_target.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (p *PushTarget) push(w http.ResponseWriter, r *http.Request) {
110110

111111
if err := p.doSendEntry(ctx, entry); err != nil {
112112
// NOTE: timeout errors can be tracked with from the metrics exposed by
113-
// the spun weaveworks server.
113+
// the spun dskit server.
114114
// loki.source.gcplog.componentid_push_target_request_duration_seconds_count{status_code="503"}
115115
level.Warn(p.logger).Log("msg", "error sending log entry", "err", err.Error())
116116
http.Error(w, err.Error(), http.StatusServiceUnavailable)

component/mimir/rules/kubernetes/rules.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/go-kit/log/level"
1111
"github.com/grafana/agent/component"
1212
mimirClient "github.com/grafana/agent/pkg/mimir/client"
13+
"github.com/grafana/dskit/instrument"
1314
promListers "github.com/prometheus-operator/prometheus-operator/pkg/client/listers/monitoring/v1"
1415
"github.com/prometheus/client_golang/prometheus"
15-
"github.com/weaveworks/common/instrument"
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1717
"k8s.io/apimachinery/pkg/labels"
1818
"k8s.io/client-go/informers"

converter/internal/staticconvert/internal/build/logging.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (b *IntegrationsV1ConfigBuilder) appendLogging(config *server.Config) {
2222
func toLogging(config *server.Config) *logging.Options {
2323
return &logging.Options{
2424
Level: logging.Level(config.LogLevel.String()),
25-
Format: logging.Format(config.LogFormat.String()),
25+
Format: logging.Format(config.LogFormat),
2626
}
2727
}

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ require (
165165
github.com/testcontainers/testcontainers-go/modules/k3s v0.0.0-20230615142642-c175df34bd1d
166166
github.com/uber/jaeger-client-go v2.30.0+incompatible
167167
github.com/vincent-petithory/dataurl v1.0.0
168-
github.com/weaveworks/common v0.0.0-20230511094633-334485600903
169168
github.com/webdevops/azure-metrics-exporter v0.0.0-20230502203721-b2bfd97b5313
170169
github.com/webdevops/go-common v0.0.0-20230502000651-d37d46be8ee7
171170
github.com/wk8/go-ordered-map v0.2.0
@@ -574,7 +573,6 @@ require (
574573
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
575574
github.com/vmware/govmomi v0.27.2 // indirect
576575
github.com/vultr/govultr/v2 v2.17.2 // indirect
577-
github.com/weaveworks/promrus v1.2.0 // indirect
578576
github.com/willf/bitset v1.1.11 // indirect
579577
github.com/willf/bloom v2.0.3+incompatible // indirect
580578
github.com/xanzy/ssh-agent v0.3.1 // indirect

0 commit comments

Comments
 (0)