-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement metrics collection for API server (#143)
- Loading branch information
Showing
12 changed files
with
401 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.