Skip to content
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

Add metric labels #612

Merged
merged 3 commits into from
Oct 1, 2024
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
13 changes: 10 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ var runCmd = &cobra.Command{
// Add clients to the pool.
for range currentPoolSize {
clientConfig := clients[configGroupName][configBlockName]
clientConfig.GroupName = configGroupName
clientConfig.BlockName = configBlockName
client := network.NewClient(
runCtx, clientConfig, logger,
network.NewRetry(
Expand All @@ -716,6 +718,7 @@ var runCmd = &cobra.Command{
if client != nil {
eventOptions := trace.WithAttributes(
attribute.String("name", configBlockName),
attribute.String("group", configGroupName),
attribute.String("network", client.Network),
attribute.String("address", client.Address),
attribute.Int("receiveChunkSize", client.ReceiveChunkSize),
Expand Down Expand Up @@ -746,6 +749,8 @@ var runCmd = &cobra.Command{

clientCfg := map[string]interface{}{
"id": client.ID,
"name": configBlockName,
"group": configGroupName,
"network": client.Network,
"address": client.Address,
"receiveChunkSize": client.ReceiveChunkSize,
Expand Down Expand Up @@ -851,7 +856,8 @@ var runCmd = &cobra.Command{
proxies[configGroupName][configBlockName] = network.NewProxy(
runCtx,
network.Proxy{
Name: configBlockName,
GroupName: configGroupName,
BlockName: configBlockName,
AvailableConnections: pools[configGroupName][configBlockName],
PluginRegistry: pluginRegistry,
HealthCheckPeriod: cfg.HealthCheckPeriod,
Expand Down Expand Up @@ -899,8 +905,9 @@ var runCmd = &cobra.Command{
servers[name] = network.NewServer(
runCtx,
network.Server{
Network: cfg.Network,
Address: cfg.Address,
GroupName: name,
Network: cfg.Network,
Address: cfg.Address,
TickInterval: config.If(
cfg.TickInterval > 0,
cfg.TickInterval,
Expand Down
3 changes: 3 additions & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type ActionRedisConfig struct {
}

type Client struct {
BlockName string `json:"-"`
GroupName string `json:"-"`

Network string `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix" yaml:"network"`
Address string `json:"address" yaml:"address"`
TCPKeepAlive bool `json:"tcpKeepAlive" yaml:"tcpKeepAlive"`
Expand Down
2 changes: 1 addition & 1 deletion gatewayd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ servers:
# Load balancer strategies can be found in config/constants.go
strategy: ROUND_ROBIN # ROUND_ROBIN, RANDOM, WEIGHTED_ROUND_ROBIN
consistentHash:
useSourceIp: true
useSourceIp: true # Set to false for using the RANDOM strategy
# Optional configuration for strategies that support rules (e.g., WEIGHTED_ROUND_ROBIN)
# loadBalancingRules:
# - condition: "DEFAULT" # Currently, only the "DEFAULT" condition is supported
Expand Down
52 changes: 26 additions & 26 deletions metrics/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ const (
)

var (
ClientConnections = promauto.NewGauge(prometheus.GaugeOpts{
ClientConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "client_connections",
Help: "Number of client connections",
})
ServerConnections = promauto.NewGauge(prometheus.GaugeOpts{
}, []string{"group", "block"})
ServerConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "server_connections",
Help: "Number of server connections",
})
TLSConnections = promauto.NewGauge(prometheus.GaugeOpts{
}, []string{"group", "block"})
TLSConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tls_connections",
Help: "Number of TLS connections",
})
}, []string{"group", "block"})
ServerTicksFired = promauto.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "server_ticks_fired_total",
Help: "Total number of server ticks fired",
})
BytesReceivedFromClient = promauto.NewSummary(prometheus.SummaryOpts{
BytesReceivedFromClient = promauto.NewSummaryVec(prometheus.SummaryOpts{
Namespace: Namespace,
Name: "bytes_received_from_client",
Help: "Number of bytes received from client",
})
BytesSentToServer = promauto.NewSummary(prometheus.SummaryOpts{
}, []string{"group", "block"})
BytesSentToServer = promauto.NewSummaryVec(prometheus.SummaryOpts{
Namespace: Namespace,
Name: "bytes_sent_to_server",
Help: "Number of bytes sent to server",
})
BytesReceivedFromServer = promauto.NewSummary(prometheus.SummaryOpts{
}, []string{"group", "block"})
BytesReceivedFromServer = promauto.NewSummaryVec(prometheus.SummaryOpts{
Namespace: Namespace,
Name: "bytes_received_from_server",
Help: "Number of bytes received from server",
})
BytesSentToClient = promauto.NewSummary(prometheus.SummaryOpts{
}, []string{"group", "block"})
BytesSentToClient = promauto.NewSummaryVec(prometheus.SummaryOpts{
Namespace: Namespace,
Name: "bytes_sent_to_client",
Help: "Number of bytes sent to client",
})
TotalTrafficBytes = promauto.NewSummary(prometheus.SummaryOpts{
}, []string{"group", "block"})
TotalTrafficBytes = promauto.NewSummaryVec(prometheus.SummaryOpts{
Namespace: Namespace,
Name: "traffic_bytes",
Help: "Number of total bytes passed through GatewayD via client or server",
})
}, []string{"group", "block"})
PluginsLoaded = promauto.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "plugins_loaded_total",
Expand All @@ -70,31 +70,31 @@ var (
Name: "plugin_hooks_executed_total",
Help: "Number of plugin hooks executed",
})
ProxyHealthChecks = promauto.NewCounter(prometheus.CounterOpts{
ProxyHealthChecks = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "proxy_health_checks_total",
Help: "Number of proxy health checks",
})
ProxiedConnections = promauto.NewGauge(prometheus.GaugeOpts{
}, []string{"group", "block"})
ProxiedConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "proxied_connections",
Help: "Number of proxy connects",
})
ProxyPassThroughsToClient = promauto.NewCounter(prometheus.CounterOpts{
}, []string{"group", "block"})
ProxyPassThroughsToClient = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "proxy_passthroughs_to_client_total",
Help: "Number of successful proxy passthroughs from server to client",
})
ProxyPassThroughsToServer = promauto.NewCounter(prometheus.CounterOpts{
}, []string{"group", "block"})
ProxyPassThroughsToServer = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "proxy_passthroughs_to_server_total",
Help: "Number of successful proxy passthroughs from client to server",
})
ProxyPassThroughTerminations = promauto.NewCounter(prometheus.CounterOpts{
}, []string{"group", "block"})
ProxyPassThroughTerminations = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "proxy_passthrough_terminations_total",
Help: "Number of proxy passthrough terminations by plugins",
})
}, []string{"group", "block"})
APIRequests = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Name: "api_requests_total",
Expand Down
11 changes: 7 additions & 4 deletions network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type Client struct {
mu sync.Mutex
retry IRetry

GroupName string
BlockName string

TCPKeepAlive bool
TCPKeepAlivePeriod time.Duration
ReceiveChunkSize int
Expand Down Expand Up @@ -168,7 +171,7 @@ func NewClient(
logger,
)

metrics.ServerConnections.Inc()
metrics.ServerConnections.WithLabelValues(clientConfig.GroupName, clientConfig.BlockName).Inc()

return &client
}
Expand Down Expand Up @@ -267,7 +270,7 @@ func (c *Client) Reconnect() error {
if c.conn != nil {
c.Close()
} else {
metrics.ServerConnections.Dec()
metrics.ServerConnections.WithLabelValues(c.GroupName, c.BlockName).Dec()
}
c.connected.Store(false)

Expand Down Expand Up @@ -306,7 +309,7 @@ func (c *Client) Reconnect() error {
)
c.connected.Store(true)
c.logger.Debug().Str("address", c.Address).Msg("Reconnected to server")
metrics.ServerConnections.Inc()
metrics.ServerConnections.WithLabelValues(c.GroupName, c.BlockName).Inc()
span.AddEvent("Reconnected to server")

return nil
Expand Down Expand Up @@ -343,7 +346,7 @@ func (c *Client) Close() {
c.Address = ""
c.Network = ""

metrics.ServerConnections.Dec()
metrics.ServerConnections.WithLabelValues(c.GroupName, c.BlockName).Dec()

span.AddEvent("Closed connection to server")
}
Expand Down
8 changes: 6 additions & 2 deletions network/network_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,15 @@ func (m MockProxy) BusyConnectionsString() []string {
return nil
}

// GetName returns the name of the MockProxy.
func (m MockProxy) GetName() string {
// GetBlockName returns the name of the MockProxy.
func (m MockProxy) GetBlockName() string {
return m.name
}

func (m MockProxy) GetGroupName() string {
return "default"
}

// Mock implementation of IConnWrapper.
type MockConnWrapper struct {
mock.Mock
Expand Down
Loading