Browse Source

zones: add structured logs to zone scanning

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/14/head
Alejandro Mery 1 year ago
parent
commit
2016b27707
  1. 21
      pkg/zones/machine_rings.go
  2. 5
      pkg/zones/machine_scan.go
  3. 20
      pkg/zones/scan.go

21
pkg/zones/machine_rings.go

@ -122,17 +122,15 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
addr := wg.GetAddress()
zoneID, nodeID, ok := Rings[ring].Decode(addr)
if !ok {
return fmt.Errorf("%s: invalid wg%v address: %s", m.Name, ring, addr)
return fmt.Errorf("%s: invalid address", addr)
}
if err := m.applyZoneNodeID(zoneID, nodeID); err != nil {
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr)
return err
return core.Wrapf(err, "%s: invalid address", addr)
}
if err := m.applyWireguardInterfaceConfig(ring, wg.Interface); err != nil {
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr)
return err
return core.Wrap(err, "interface")
}
for _, peer := range wg.Peer {
@ -140,9 +138,14 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
switch {
case errors.Is(err, ErrUnknownNode):
// ignore unknown peers
m.warn(nil).
WithField("subsystem", "wireguard").
WithField("node", m.Name).
WithField("peer", peer.Endpoint.Host).
WithField("ring", ring).
Print("ignoring unknown endpoint")
case err != nil:
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr)
return err
return core.Wrap(err, "peer")
}
}
@ -163,6 +166,10 @@ func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
cur, _ := m.getRingInfo(ring)
if cur == nil {
// first, append
m.debug().
WithField("node", m.Name).
WithField("ring", ring).
Print("found")
m.Rings = append(m.Rings, new)
return nil
}

5
pkg/zones/machine_scan.go

@ -71,6 +71,11 @@ func (m *Machine) setID() error {
func (m *Machine) scan(opts *ScanOptions) error {
for i := 0; i < RingsCount; i++ {
if err := m.tryApplyWireguardConfig(i); err != nil {
m.error(err).
WithField("subsystem", "wireguard").
WithField("node", m.Name).
WithField("ring", i).
Print()
return err
}
}

20
pkg/zones/scan.go

@ -37,7 +37,11 @@ func (m *Zones) scanDirectory(_ *ScanOptions) error {
switch {
case err != nil:
return core.Wrap(err, e.Name())
case z.Machines.Len() > 0:
case z.Machines.Len() == 0:
z.warn(nil).
WithField("zone", z.Name).
Print("empty")
default:
m.Zones = append(m.Zones, z)
}
}
@ -53,6 +57,10 @@ func (m *Zones) newZone(name string) (*Zone, error) {
Name: name,
}
z.debug().
WithField("zone", z.Name).
Print("found")
if err := z.scan(); err != nil {
return nil, err
}
@ -149,7 +157,17 @@ func (z *Zone) scan() error {
Name: e.Name(),
}
m.debug().
WithField("node", m.Name).
WithField("zone", z.Name).
Print("found")
if err := m.init(); err != nil {
m.error(err).
WithField("node", m.Name).
WithField("zone", z.Name).
Print()
return err
}

Loading…
Cancel
Save