Skip to content

Commit 7cea98a

Browse files
ldebruijnldebruijn
andauthored
Fix gauges, add App-Info metric and reduce max-token default limit (#14)
Number of small additions and fixes: - Fix gauge measures to behave like gauges, instead of counters - Add app-info gauge with information about go-graphql-armor - Reduce default max-token config to a more sane number --------- Co-authored-by: ldebruijn <[email protected]>
1 parent 3d75a59 commit 7cea98a

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

cmd/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,19 @@ var (
5353
},
5454
[]string{"route"},
5555
)
56+
57+
appInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
58+
Namespace: "go_graphql_armor",
59+
Subsystem: "app",
60+
Name: "info",
61+
Help: "Application information",
62+
},
63+
[]string{"version", "go_version"},
64+
)
5665
)
5766

5867
func init() {
59-
prometheus.MustRegister(httpCounter, httpDuration)
68+
prometheus.MustRegister(httpCounter, httpDuration, appInfo)
6069
}
6170

6271
func main() {
@@ -76,6 +85,11 @@ func main() {
7685

7786
log.Info("Starting service", "version", build)
7887

88+
appInfo.With(prometheus.Labels{
89+
"version": build,
90+
"go_version": runtime.Version(),
91+
})
92+
7993
shutdown := make(chan os.Signal, 1)
8094
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
8195

docs/max_tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ max_tokens:
1414
# Enable the feature
1515
enable: "true"
1616
# The maximum number of allowed tokens within a single request.
17-
max: 10000
17+
max: 1000
1818
# Reject the request when the rule fails. Disable this to allow the request regardless of token count.
1919
reject_on_failure: "true"
2020
```

internal/business/persisted_operations/persisted_operations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (p *PersistedOperationsHandler) reloadFromLocalDir() error {
208208
p.lock.Unlock()
209209

210210
p.log.Info("Loaded persisted operations", "amount", len(cache))
211-
reloadGauge.WithLabelValues("local").Inc()
211+
reloadGauge.WithLabelValues("local").Set(1)
212212

213213
return nil
214214
}
@@ -229,7 +229,7 @@ func (p *PersistedOperationsHandler) reload() {
229229
if err != nil {
230230
p.log.Warn("Error loading from local dir", "err", err)
231231
}
232-
reloadGauge.WithLabelValues("ticker").Inc()
232+
reloadGauge.WithLabelValues("ticker").Set(1)
233233
}
234234
}
235235
}()
@@ -248,7 +248,7 @@ func (p *PersistedOperationsHandler) reloadFromRemote() {
248248
return
249249
}
250250

251-
reloadGauge.WithLabelValues("remote").Inc()
251+
reloadGauge.WithLabelValues("remote").Set(1)
252252
}
253253

254254
func (p *PersistedOperationsHandler) Shutdown() {

internal/business/tokens/tokens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var resultCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
1818

1919
type Config struct {
2020
Enabled bool `conf:"default:true" yaml:"enabled"`
21-
Max int `conf:"default:10000" yaml:"max"`
21+
Max int `conf:"default:1000" yaml:"max"`
2222
RejectOnFailure bool `conf:"default:true" yaml:"reject-on-failure"`
2323
}
2424

0 commit comments

Comments
 (0)