Skip to content

Commit b12dddd

Browse files
authored
Merge pull request #53 from gatewayd-io/method-call-counter-metrics
Method call counter metrics
2 parents 08c6d19 + b9914e6 commit b12dddd

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

plugin/metrics.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ import (
77
)
88

99
var (
10+
GetPluginConfigCounter = promauto.NewCounter(prometheus.CounterOpts{
11+
Namespace: metrics.Namespace,
12+
Name: "get_plugin_config_total",
13+
Help: "The total number of calls to the getPluginConfig method",
14+
})
15+
OnClosedCounter = promauto.NewCounter(prometheus.CounterOpts{
16+
Namespace: metrics.Namespace,
17+
Name: "on_closed_total",
18+
Help: "The total number of calls to the onClosed method",
19+
})
20+
OnTrafficFromClientCounter = promauto.NewCounter(prometheus.CounterOpts{
21+
Namespace: metrics.Namespace,
22+
Name: "on_traffic_from_client_total",
23+
Help: "The total number of calls to the onTrafficFromClient method",
24+
})
25+
OnTrafficFromServerCounter = promauto.NewCounter(prometheus.CounterOpts{
26+
Namespace: metrics.Namespace,
27+
Name: "on_traffic_from_server_total",
28+
Help: "The total number of calls to the onTrafficFromServer method",
29+
})
30+
1031
CacheHitsCounter = promauto.NewCounter(prometheus.CounterOpts{
1132
Namespace: metrics.Namespace,
1233
Name: "cache_hits_total",

plugin/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ func (p *CachePlugin) GRPCClient(_ context.Context, _ *goplugin.GRPCBroker, c *g
6565
func (p *Plugin) GetPluginConfig(
6666
_ context.Context, _ *structpb.Struct,
6767
) (*structpb.Struct, error) {
68+
GetPluginConfigCounter.Inc()
6869
return structpb.NewStruct(PluginConfig)
6970
}
7071

7172
// OnTrafficFromClient is called when a request is received by GatewayD from the client.
7273
func (p *Plugin) OnTrafficFromClient(
7374
ctx context.Context, req *structpb.Struct,
7475
) (*structpb.Struct, error) {
76+
OnTrafficFromClientCounter.Inc()
7577
req, err := postgres.HandleClientMessage(req, p.Logger)
7678
if err != nil {
7779
p.Logger.Info("Failed to handle client message", "error", err)
@@ -147,6 +149,7 @@ func (p *Plugin) OnTrafficFromClient(
147149
func (p *Plugin) OnTrafficFromServer(
148150
ctx context.Context, resp *structpb.Struct,
149151
) (*structpb.Struct, error) {
152+
OnTrafficFromServerCounter.Inc()
150153
resp, err := postgres.HandleServerMessage(resp, p.Logger)
151154
if err != nil {
152155
p.Logger.Info("Failed to handle server message", "error", err)
@@ -221,6 +224,7 @@ func (p *Plugin) OnTrafficFromServer(
221224
}
222225

223226
func (p *Plugin) OnClosed(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error) {
227+
OnClosedCounter.Inc()
224228
client := cast.ToStringMapString(sdkPlugin.GetAttr(req, "client", nil))
225229
if client != nil {
226230
if err := p.RedisClient.Del(ctx, client["remote"]).Err(); err != nil {

0 commit comments

Comments
 (0)