mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
Add tracing annotations
This patch changes several internal packages to receive and pass tracing annotations, making use of the new tracing library, so we can have better debugging information.
This commit is contained in:
@@ -75,8 +75,8 @@ func (db *DB) Reload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) write(d *Domain) {
|
||||
tr := trace.New("DomainInfo.write", d.Name)
|
||||
func (db *DB) write(tr *trace.Trace, d *Domain) {
|
||||
tr = tr.NewChild("DomainInfo.write", d.Name)
|
||||
defer tr.Finish()
|
||||
|
||||
err := db.store.Put(d.Name, d)
|
||||
@@ -89,8 +89,8 @@ func (db *DB) write(d *Domain) {
|
||||
|
||||
// IncomingSecLevel checks an incoming security level for the domain.
|
||||
// Returns true if allowed, false otherwise.
|
||||
func (db *DB) IncomingSecLevel(domain string, level SecLevel) bool {
|
||||
tr := trace.New("DomainInfo.Incoming", domain)
|
||||
func (db *DB) IncomingSecLevel(tr *trace.Trace, domain string, level SecLevel) bool {
|
||||
tr = tr.NewChild("DomainInfo.Incoming", domain)
|
||||
defer tr.Finish()
|
||||
tr.Debugf("incoming at level %s", level)
|
||||
|
||||
@@ -101,7 +101,7 @@ func (db *DB) IncomingSecLevel(domain string, level SecLevel) bool {
|
||||
if !exists {
|
||||
d = &Domain{Name: domain}
|
||||
db.info[domain] = d
|
||||
defer db.write(d)
|
||||
defer db.write(tr, d)
|
||||
}
|
||||
|
||||
if level < d.IncomingSecLevel {
|
||||
@@ -117,7 +117,7 @@ func (db *DB) IncomingSecLevel(domain string, level SecLevel) bool {
|
||||
d.Name, level, d.IncomingSecLevel)
|
||||
d.IncomingSecLevel = level
|
||||
if exists {
|
||||
defer db.write(d)
|
||||
defer db.write(tr, d)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -125,8 +125,8 @@ func (db *DB) IncomingSecLevel(domain string, level SecLevel) bool {
|
||||
|
||||
// OutgoingSecLevel checks an incoming security level for the domain.
|
||||
// Returns true if allowed, false otherwise.
|
||||
func (db *DB) OutgoingSecLevel(domain string, level SecLevel) bool {
|
||||
tr := trace.New("DomainInfo.Outgoing", domain)
|
||||
func (db *DB) OutgoingSecLevel(tr *trace.Trace, domain string, level SecLevel) bool {
|
||||
tr = tr.NewChild("DomainInfo.Outgoing", domain)
|
||||
defer tr.Finish()
|
||||
tr.Debugf("outgoing at level %s", level)
|
||||
|
||||
@@ -137,7 +137,7 @@ func (db *DB) OutgoingSecLevel(domain string, level SecLevel) bool {
|
||||
if !exists {
|
||||
d = &Domain{Name: domain}
|
||||
db.info[domain] = d
|
||||
defer db.write(d)
|
||||
defer db.write(tr, d)
|
||||
}
|
||||
|
||||
if level < d.OutgoingSecLevel {
|
||||
@@ -153,7 +153,7 @@ func (db *DB) OutgoingSecLevel(domain string, level SecLevel) bool {
|
||||
d.Name, level, d.OutgoingSecLevel)
|
||||
d.OutgoingSecLevel = level
|
||||
if exists {
|
||||
defer db.write(d)
|
||||
defer db.write(tr, d)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/testlib"
|
||||
"blitiri.com.ar/go/chasquid/internal/trace"
|
||||
)
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
@@ -13,14 +14,16 @@ func TestBasic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
if !db.IncomingSecLevel("d1", SecLevel_PLAIN) {
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_PLAIN) {
|
||||
t.Errorf("new domain as plain not allowed")
|
||||
}
|
||||
if !db.IncomingSecLevel("d1", SecLevel_TLS_SECURE) {
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_TLS_SECURE) {
|
||||
t.Errorf("increment to tls-secure not allowed")
|
||||
}
|
||||
if db.IncomingSecLevel("d1", SecLevel_TLS_INSECURE) {
|
||||
if db.IncomingSecLevel(tr, "d1", SecLevel_TLS_INSECURE) {
|
||||
t.Errorf("decrement to tls-insecure was allowed")
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ func TestBasic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if db2.IncomingSecLevel("d1", SecLevel_TLS_INSECURE) {
|
||||
if db2.IncomingSecLevel(tr, "d1", SecLevel_TLS_INSECURE) {
|
||||
t.Errorf("decrement to tls-insecure was allowed in new DB")
|
||||
}
|
||||
}
|
||||
@@ -41,6 +44,8 @@ func TestNewDomain(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
cases := []struct {
|
||||
domain string
|
||||
@@ -51,10 +56,10 @@ func TestNewDomain(t *testing.T) {
|
||||
{"secure", SecLevel_TLS_SECURE},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if !db.IncomingSecLevel(c.domain, c.level) {
|
||||
if !db.IncomingSecLevel(tr, c.domain, c.level) {
|
||||
t.Errorf("domain %q not allowed (in) at %s", c.domain, c.level)
|
||||
}
|
||||
if !db.OutgoingSecLevel(c.domain, c.level) {
|
||||
if !db.OutgoingSecLevel(tr, c.domain, c.level) {
|
||||
t.Errorf("domain %q not allowed (out) at %s", c.domain, c.level)
|
||||
}
|
||||
}
|
||||
@@ -67,6 +72,8 @@ func TestProgressions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
cases := []struct {
|
||||
domain string
|
||||
@@ -85,11 +92,11 @@ func TestProgressions(t *testing.T) {
|
||||
{"ssip", SecLevel_PLAIN, false},
|
||||
}
|
||||
for i, c := range cases {
|
||||
if ok := db.IncomingSecLevel(c.domain, c.lvl); ok != c.ok {
|
||||
if ok := db.IncomingSecLevel(tr, c.domain, c.lvl); ok != c.ok {
|
||||
t.Errorf("%2d %q in attempt for %s failed: got %v, expected %v",
|
||||
i, c.domain, c.lvl, ok, c.ok)
|
||||
}
|
||||
if ok := db.OutgoingSecLevel(c.domain, c.lvl); ok != c.ok {
|
||||
if ok := db.OutgoingSecLevel(tr, c.domain, c.lvl); ok != c.ok {
|
||||
t.Errorf("%2d %q out attempt for %s failed: got %v, expected %v",
|
||||
i, c.domain, c.lvl, ok, c.ok)
|
||||
}
|
||||
@@ -111,7 +118,10 @@ func TestErrors(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !db.IncomingSecLevel("d1", SecLevel_TLS_SECURE) {
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_TLS_SECURE) {
|
||||
t.Errorf("increment to tls-secure not allowed")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user