diff options
author | Rasmus Dahlberg <rgdd@glasklarteknik.se> | 2025-05-11 20:07:41 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rgdd@glasklarteknik.se> | 2025-05-11 20:23:33 +0200 |
commit | f073493c3d11a4d743f0ee1c3f4b423c51f60e29 (patch) | |
tree | 3aafdeb2d3ddd1ec898468897a6e759bf2a7e709 /pkg/storage | |
parent | 5285be7f31ea8c043566e4e9f1ed5acd50168837 (diff) |
metrics: Add human-meaningful log_name labelmain
Use log metadata description if available, otherwise fall back on log
URL without the https:// suffix.
Keeping log_id for now at least - seems useful for scripts.
Diffstat (limited to 'pkg/storage')
-rw-r--r-- | pkg/storage/loglist/loglist.go | 4 | ||||
-rw-r--r-- | pkg/storage/loglist/metadata.go | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/pkg/storage/loglist/loglist.go b/pkg/storage/loglist/loglist.go index a37cb32..f282113 100644 --- a/pkg/storage/loglist/loglist.go +++ b/pkg/storage/loglist/loglist.go @@ -72,6 +72,10 @@ func New(cfg Config) (LogList, error) { return ll, nil } +func (ll *LogList) LogName(logID [32]byte) (string, error) { + return metadataLogName(ll.md, logID) +} + func (ll *LogList) IsRecent() bool { return time.Now().Before(ll.md.CreatedAt.Add(ll.cfg.MetadataIsRecent)) } diff --git a/pkg/storage/loglist/metadata.go b/pkg/storage/loglist/metadata.go index adacf81..96d035c 100644 --- a/pkg/storage/loglist/metadata.go +++ b/pkg/storage/loglist/metadata.go @@ -1,6 +1,11 @@ package loglist -import "gitlab.torproject.org/rgdd/ct/pkg/metadata" +import ( + "fmt" + "strings" + + "gitlab.torproject.org/rgdd/ct/pkg/metadata" +) // FIXME: helpers that should probably be in the upstream package @@ -13,6 +18,25 @@ func metadataFindLog(md metadata.Metadata, target metadata.Log) bool { return false } +func metadataLogName(md metadata.Metadata, targetID [32]byte) (string, error) { + for _, operator := range md.Operators { + for _, log := range operator.Logs { + id, _ := log.Key.ID() + if id == targetID { + return FormatLogName(log), nil + } + } + } + return "", fmt.Errorf("no match for log ID: %x", targetID[:]) +} + +func FormatLogName(log metadata.Log) string { + if log.Description != nil { + return *log.Description + } + return strings.TrimSuffix("https://", string(log.URL)) +} + func findLog(logs []metadata.Log, target metadata.Log) bool { targetID, _ := target.Key.ID() for _, log := range logs { |