forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetdump.go
More file actions
70 lines (62 loc) · 2.05 KB
/
netdump.go
File metadata and controls
70 lines (62 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2022 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package dpcmanager
import (
"time"
"github.com/lf-edge/eve/pkg/pillar/netdump"
"github.com/lf-edge/eve/pkg/pillar/types"
"github.com/lf-edge/eve/pkg/pillar/zboot"
)
// Topic for netdumps of successful connectivity tests.
func (m *DpcManager) netDumpOKTopic() string {
return m.AgentName + "-ok"
}
// Topic for netdumps of failed connectivity tests.
func (m *DpcManager) netDumpFailTopic() string {
return m.AgentName + "-fail"
}
// Function decides if the next call to TestConnectivity should be traced
// and netdump published at the end (see libs/nettrace and pkg/pillar/netdump).
func (m *DpcManager) traceNextConnTest() bool {
if m.netDumper == nil || m.netdumpInterval == 0 {
return false
}
// Trace only if the highest priority DPC is currently being used.
// Traces are used for troubleshooting purposes and there is no point
// in troubleshooting obsolete DPCs.
if len(m.dpcList.PortConfigList) == 0 || m.dpcList.CurrentIndex != 0 {
return false
}
if m.lastNetdumpPub.IsZero() {
// No netdump published yet for DPC testing.
return true
}
uptime := time.Since(m.startTime)
lastNetdumpAge := time.Since(m.lastNetdumpPub)
// Ensure we get at least one netdump for the currently tested EVE upgrade.
if zboot.IsCurrentPartitionStateInProgress() && lastNetdumpAge > uptime {
return true
}
return lastNetdumpAge >= m.netdumpInterval
}
// Publish netdump containing traces of executed connectivity probes.
func (m *DpcManager) publishNetdump(
controllerConnWorks bool, tracedConnProbes []netdump.TracedNetRequest) {
netDumper := m.netDumper
if netDumper == nil {
return
}
var topic string
if controllerConnWorks {
topic = m.netDumpOKTopic()
} else {
topic = m.netDumpFailTopic()
}
filename, err := netDumper.Publish(topic, types.NetTraceFolder, tracedConnProbes...)
if err != nil {
m.Log.Warnf("Failed to publish netdump for topic %s: %v", topic, err)
} else {
m.Log.Noticef("Published netdump for topic %s: %s", topic, filename)
}
m.lastNetdumpPub = time.Now()
}