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

Fix gauges, add App-Info metric and reduce max-token default limit #14

Merged
merged 3 commits into from
Jan 9, 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
16 changes: 15 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ var (
},
[]string{"route"},
)

appInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "go_graphql_armor",
Subsystem: "app",
Name: "info",
Help: "Application information",
},
[]string{"version", "go_version"},
)
)

func init() {
prometheus.MustRegister(httpCounter, httpDuration)
prometheus.MustRegister(httpCounter, httpDuration, appInfo)
}

func main() {
Expand All @@ -76,6 +85,11 @@ func main() {

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

appInfo.With(prometheus.Labels{
"version": build,
"go_version": runtime.Version(),
})

shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)

Expand Down
2 changes: 1 addition & 1 deletion docs/max_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ max_tokens:
# Enable the feature
enable: "true"
# The maximum number of allowed tokens within a single request.
max: 10000
max: 1000
# Reject the request when the rule fails. Disable this to allow the request regardless of token count.
reject_on_failure: "true"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (p *PersistedOperationsHandler) reloadFromLocalDir() error {
p.lock.Unlock()

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

return nil
}
Expand All @@ -229,7 +229,7 @@ func (p *PersistedOperationsHandler) reload() {
if err != nil {
p.log.Warn("Error loading from local dir", "err", err)
}
reloadGauge.WithLabelValues("ticker").Inc()
reloadGauge.WithLabelValues("ticker").Set(1)
}
}
}()
Expand All @@ -248,7 +248,7 @@ func (p *PersistedOperationsHandler) reloadFromRemote() {
return
}

reloadGauge.WithLabelValues("remote").Inc()
reloadGauge.WithLabelValues("remote").Set(1)
}

func (p *PersistedOperationsHandler) Shutdown() {
Expand Down
2 changes: 1 addition & 1 deletion internal/business/tokens/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var resultCounter = prometheus.NewCounterVec(prometheus.CounterOpts{

type Config struct {
Enabled bool `conf:"default:true" yaml:"enabled"`
Max int `conf:"default:10000" yaml:"max"`
Max int `conf:"default:1000" yaml:"max"`
RejectOnFailure bool `conf:"default:true" yaml:"reject-on-failure"`
}

Expand Down
Empty file added schema.graphql
Empty file.