mirror of
https://github.com/Luzifer/ots.git
synced 2025-08-01 18:56:04 -04:00
Implement metrics collection for API server (#143)
This commit is contained in:
parent
1623e09225
commit
5ad6449757
12 changed files with 402 additions and 95 deletions
52
helpers.go
Normal file
52
helpers.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/Luzifer/ots/pkg/metrics"
|
||||
"github.com/Luzifer/ots/pkg/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func requestInSubnetList(r *http.Request, subnets []string) bool {
|
||||
if len(subnets) == 0 {
|
||||
// No subnets specififed: None allowed (without doing the parsing)
|
||||
return false
|
||||
}
|
||||
|
||||
remote, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("parsing remote address")
|
||||
return false
|
||||
}
|
||||
|
||||
remoteIP := net.ParseIP(remote)
|
||||
if remoteIP == nil {
|
||||
logrus.WithError(err).Error("parsing remote address")
|
||||
return false
|
||||
}
|
||||
|
||||
for _, sn := range subnets {
|
||||
_, netw, err := net.ParseCIDR(sn)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("subnet", sn).Warn("invalid subnet specified")
|
||||
continue
|
||||
}
|
||||
|
||||
if netw.Contains(remoteIP) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func updateStoredSecretsCount(store storage.Storage, collector *metrics.Collector) {
|
||||
n, err := store.Count()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("counting stored secrets")
|
||||
return
|
||||
}
|
||||
collector.UpdateSecretsCount(n)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue