Skip to content

Commit cca5a07

Browse files
committed
Add logging to help figure out CI failures
1 parent f757d0f commit cca5a07

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

.github/workflows/unit-test-on-pull-request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ jobs:
246246
kernel:
247247
- 5.10.217 # Pre-6.6, uses single-shot mode
248248
- 6.8.10 # Post-6.6, supports multi-uprobe
249+
- 6.12.16
250+
- 6.16
249251
steps:
250252
- name: Clone code
251253
uses: actions/checkout@v4

interpreter/rtld/rtld.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ type instance struct {
2828
// Loader detects if the ELF file contains the dlopen symbol in its dynamic symbol table
2929
func Loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpreter.Data, error) {
3030
fileName := info.FileName()
31+
log.Infof("[dlopen] Loader called for file: %s", fileName)
3132

3233
ef, err := info.GetELF()
3334
if err != nil {
35+
log.Debugf("[dlopen] Failed to get ELF for %s: %v", fileName, err)
3436
return nil, err
3537
}
3638

3739
// Look for the dlopen symbol in the dynamic symbol table
3840
sym, err := ef.LookupSymbol("dlopen")
3941
if err != nil || sym == nil {
4042
// No dlopen symbol found, this library doesn't support dynamic loading
43+
log.Debugf("[dlopen] No dlopen symbol found in %s", fileName)
4144
return nil, nil
4245
}
4346

44-
log.Debugf("Found dlopen symbol in %s at 0x%x", fileName, sym.Address)
47+
log.Infof("[dlopen] Found dlopen symbol in %s at 0x%x", fileName, sym.Address)
4548

4649
return &data{
4750
path: fileName,
@@ -52,13 +55,16 @@ func Loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpr
5255
// Attach attaches the uprobe to the dlopen function
5356
func (d *data) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libpf.Address,
5457
_ remotememory.RemoteMemory) (interpreter.Instance, error) {
58+
log.Infof("[dlopen] Attempting to attach uprobe for PID %d on %s at 0x%x", pid, d.path, d.address)
59+
5560
// Attach uprobe to dlopen using the address stored during Loader
5661
lc, err := ebpf.AttachUprobe(pid, d.path, d.address, "uprobe_dlopen")
5762
if err != nil {
63+
log.Errorf("[dlopen] Failed to attach uprobe to dlopen for PID %d: %v", pid, err)
5864
return nil, fmt.Errorf("failed to attach uprobe to dlopen: %w", err)
5965
}
6066

61-
log.Debugf("[dlopen] Attached uprobe to dlopen for PID %d on %s at 0x%x",
67+
log.Infof("[dlopen] Successfully attached uprobe to dlopen for PID %d on %s at 0x%x",
6268
pid, d.path, d.address)
6369

6470
d.lc = lc

interpreter/rtld/rtld_test.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,31 @@ func TestIntegrationSingleShot(t *testing.T) {
8080
t.Skip("This test requires root privileges")
8181
}
8282

83+
// Enable info logging to see uprobe attachment
84+
log.SetLevel(log.InfoLevel)
85+
8386
// Enable debug logging for CI debugging
8487
if os.Getenv("DEBUG_TEST") != "" {
8588
log.SetLevel(log.DebugLevel)
8689
}
8790

91+
t.Logf("Test process PID: %d", os.Getpid())
92+
93+
// Check which libraries are available and contain dlopen
94+
t.Logf("Checking for dlopen-containing libraries...")
95+
possibleLibs := []string{
96+
"/lib/x86_64-linux-gnu/libc.so.6",
97+
"/lib64/libc.so.6",
98+
"/usr/lib/x86_64-linux-gnu/libc.so.6",
99+
"/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2",
100+
"/lib64/ld-linux-x86-64.so.2",
101+
}
102+
for _, lib := range possibleLibs {
103+
if _, err := os.Stat(lib); err == nil {
104+
t.Logf("Found library: %s", lib)
105+
}
106+
}
107+
88108
// Override HasMultiUprobeSupport to force single-shot mode
89109
multiUProbeOverride := false
90110
util.SetTestOnlyMultiUprobeSupport(&multiUProbeOverride)
@@ -95,10 +115,12 @@ func TestIntegrationSingleShot(t *testing.T) {
95115
defer cancel()
96116

97117
// Start the tracer with all tracers enabled
118+
t.Logf("Starting tracer...")
98119
traceCh, trc := testutils.StartTracer(ctx, t,
99120
tracertypes.AllTracers(),
100121
false)
101122
defer trc.Close()
123+
t.Logf("Tracer started successfully")
102124

103125
// Consume traces to prevent blocking
104126
go func() {
@@ -117,23 +139,32 @@ func TestIntegrationSingleShot(t *testing.T) {
117139
require.Eventually(t, func() bool {
118140
// Get the initial metric value
119141
initialCount := getEBPFMetricValue(trc, metrics.IDDlopenUprobeHits)
120-
//t.Logf("Initial dlopen uprobe metric count: %d", initialCount)
142+
t.Logf("Initial dlopen uprobe metric count: %d", initialCount)
121143

122144
// Use dlopen to load a shared library
123145
// libm is a standard math library that's always present
124146
lib, err := dlopen.GetHandle([]string{
125147
"/lib/x86_64-linux-gnu/libm.so.6",
126148
"libm.so.6",
127149
})
128-
require.NoError(t, err, "Failed to open libm.so.6")
150+
if err != nil {
151+
t.Logf("Failed to open libm.so.6: %v", err)
152+
require.NoError(t, err, "Failed to open libm.so.6")
153+
}
154+
t.Logf("Successfully opened libm.so.6")
129155
defer lib.Close()
130156

131157
// Get the metrics after dlopen
132158
finalCount := getEBPFMetricValue(trc, metrics.IDDlopenUprobeHits)
133-
//t.Logf("Final dlopen uprobe metric count: %d", finalCount)
159+
t.Logf("Final dlopen uprobe metric count: %d (delta: %d)", finalCount, finalCount-initialCount)
134160

135161
// Check that the metric was incremented
136-
return finalCount > initialCount
162+
if finalCount > initialCount {
163+
t.Logf("SUCCESS: Metric incremented from %d to %d", initialCount, finalCount)
164+
return true
165+
}
166+
t.Logf("Metric not incremented yet, retrying...")
167+
return false
137168
}, 10*time.Second, 50*time.Millisecond)
138169
}
139170

@@ -142,21 +173,29 @@ func getEBPFMetricValue(trc *tracer.Tracer, metricID metrics.MetricID) uint64 {
142173
ebpfMaps := trc.GetEbpfMaps()
143174
metricsMap, ok := ebpfMaps["metrics"]
144175
if !ok {
176+
log.Debugf("Metrics map not found in eBPF maps")
145177
return 0
146178
}
147179

148180
// Find the eBPF metric ID that corresponds to our metrics.MetricID
149181
var ebpfMetricID uint32
182+
found := false
150183
for ebpfID, id := range support.MetricsTranslation {
151184
if id == metricID {
152185
ebpfMetricID = uint32(ebpfID)
186+
found = true
153187
break
154188
}
155189
}
190+
if !found {
191+
log.Debugf("Metric ID %v not found in MetricsTranslation", metricID)
192+
return 0
193+
}
156194

157195
// Read the per-CPU values
158196
var perCPUValues []uint64
159197
if err := metricsMap.Lookup(unsafe.Pointer(&ebpfMetricID), &perCPUValues); err != nil {
198+
log.Debugf("Failed to lookup metric %v (eBPF ID %d): %v", metricID, ebpfMetricID, err)
160199
return 0
161200
}
162201

@@ -165,5 +204,6 @@ func getEBPFMetricValue(trc *tracer.Tracer, metricID metrics.MetricID) uint64 {
165204
for _, val := range perCPUValues {
166205
total += val
167206
}
207+
log.Debugf("Metric %v (eBPF ID %d): total=%d from %d CPUs", metricID, ebpfMetricID, total, len(perCPUValues))
168208
return total
169209
}

0 commit comments

Comments
 (0)