feat(observability): add product metrics for API, outbox and delivery
This commit is contained in:
1 parent
560724e2aa
commit
94488e2b57
51 files changed
+3655
-68
No files matched your search
@@ -0,0 +1,19 @@
|
||||
package testutil
|
||||
|
||||
import "regexp"
|
||||
|
||||
var (
|
||||
// emailLike matches an address anywhere in a text, for example inside a
|
||||
// metric label value or a log line.
|
||||
emailLike = regexp.MustCompile(`[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}`)
|
||||
// uuidLike matches the canonical text form of a UUID, the form of user,
|
||||
// delivery, attempt, and document IDs.
|
||||
uuidLike = regexp.MustCompile(`[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}`)
|
||||
)
|
||||
|
||||
// FindPersonalIdentifiers returns every email-like and UUID-like substring of
|
||||
// text. Tests use it on a metrics exposition or a log to prove that no
|
||||
// address or entity ID leaked into labels or messages.
|
||||
func FindPersonalIdentifiers(text string) []string {
|
||||
return append(emailLike.FindAllString(text, -1), uuidLike.FindAllString(text, -1)...)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindPersonalIdentifiers(t *testing.T) {
|
||||
text := `a{route="/x",user="Jane.Doe+tag@mail.example.org"} 1` + "\n" +
|
||||
`b{id="0199b4f2-7c1e-7d3a-9f00-AABBCCDDEEFF"} 1` + "\n" +
|
||||
`c{route="/api/v1/me/invitations/{invitationId}",status="404"} 1`
|
||||
got := FindPersonalIdentifiers(text)
|
||||
want := []string{"Jane.Doe+tag@mail.example.org", "0199b4f2-7c1e-7d3a-9f00-AABBCCDDEEFF"}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("FindPersonalIdentifiers() = %q, want %q", got, want)
|
||||
}
|
||||
if found := FindPersonalIdentifiers(`go_info{version="go1.26.8"} 1`); len(found) != 0 {
|
||||
t.Fatalf("FindPersonalIdentifiers() reported %q in a clean text", found)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user