Skip to content

Commit 8f82833

Browse files
authored
Bump key size to 25 (#162)
1 parent e8c621a commit 8f82833

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

interpreter/golabels/integrationtests/golabels_integration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ func Test_Golabels(t *testing.T) {
141141
require.True(t, strings.HasPrefix(v, "label2"))
142142
hits |= (1 << 1)
143143
} else if strings.HasPrefix(k, "l3") {
144-
require.Len(t, v, 47)
144+
// The maximum. Bump this, and
145+
// the value in pprof_test.go, if
146+
// CUSTOM_LABEL_MAX_VAL_LEN changes.
147+
require.Len(t, v, 53)
145148
require.True(t, strings.HasPrefix(v, "label3"))
146149
hits |= (1 << 2)
147150
}

interpreter/golabels/integrationtests/pprof/pprof_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func setPprofLabels(t *testing.T, ctx context.Context, cookie string, busyFunc f
2727
labels := pprof.Labels(
2828
"l1"+cookie, "label1"+randomString(16),
2929
"l2"+cookie, "label2"+randomString(24),
30-
"l3"+cookie, "label3"+randomString(48))
30+
// One more than the maximum -- in golabels_integration_test.go
31+
// we will see it get cut off.
32+
"l3"+cookie, "label3"+randomString(54))
3133
lastUpdate := time.Now()
3234
pprof.Do(ctx, labels, func(context.Context) {
3335
for time.Since(lastUpdate) < 10*time.Second {

support/ebpf/go_labels.ebpf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ get_go_custom_labels_from_slice(PerCPURecord *record, void *labels_slice_ptr)
3030
if (i >= labels_slice.len)
3131
break;
3232
CustomLabel *lbl = &out->labels[i];
33-
u8 klen = MIN(record->labels[i * 2].len, CUSTOM_LABEL_MAX_KEY_LEN - 1);
33+
u8 klen = MIN(record->labels[i * 2].len, CUSTOM_LABEL_MAX_KEY_LEN);
3434
if (bpf_probe_read_user(lbl->key, klen, record->labels[i * 2].str)) {
3535
DEBUG_PRINT(
3636
"cl: failed to read key for custom label (%lx)", (unsigned long)record->labels[i * 2].str);
3737
return false;
3838
}
39-
u8 vlen = MIN(record->labels[i * 2 + 1].len, CUSTOM_LABEL_MAX_VAL_LEN - 1);
39+
u8 vlen = MIN(record->labels[i * 2 + 1].len, CUSTOM_LABEL_MAX_VAL_LEN);
4040
if (bpf_probe_read_user(lbl->val, vlen, record->labels[i * 2 + 1].str)) {
4141
DEBUG_PRINT(
4242
"cl: failed to read key for custom label (%lx)",
@@ -110,11 +110,11 @@ get_go_custom_labels_from_map(PerCPURecord *record, void *labels_map_ptr_ptr, Go
110110
char *vstr = map_value->values[i].str;
111111
unsigned vlen = map_value->values[i].len;
112112
if (tophash != 0 && kstr != NULL) {
113-
if (bpf_probe_read_user(lbl->key, MIN(klen, CUSTOM_LABEL_MAX_KEY_LEN - 1), kstr)) {
113+
if (bpf_probe_read_user(lbl->key, MIN(klen, CUSTOM_LABEL_MAX_KEY_LEN), kstr)) {
114114
DEBUG_PRINT("cl: failed to read key for custom label (%lx)", (unsigned long)kstr);
115115
return false;
116116
}
117-
if (bpf_probe_read_user(lbl->val, MIN(vlen, CUSTOM_LABEL_MAX_VAL_LEN - 1), vstr)) {
117+
if (bpf_probe_read_user(lbl->val, MIN(vlen, CUSTOM_LABEL_MAX_VAL_LEN), vstr)) {
118118
DEBUG_PRINT("cl: failed to read value for custom label");
119119
return false;
120120
}

support/ebpf/interpreter_dispatcher.ebpf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ read_labelset_into_trace(PerCPURecord *record, NativeCustomLabelsSet *p_current_
355355
if (!lbl->key.buf)
356356
continue;
357357
CustomLabel *out_lbl = &out->labels[ct];
358-
unsigned klen = MIN(lbl->key.len, CUSTOM_LABEL_MAX_KEY_LEN - 1);
358+
unsigned klen = MIN(lbl->key.len, CUSTOM_LABEL_MAX_KEY_LEN);
359359
if ((err = bpf_probe_read_user(out_lbl->key, klen, (void *)lbl->key.buf))) {
360360
increment_metric(metricID_UnwindNativeCustomLabelsErrReadKey);
361361
DEBUG_PRINT("cl: failed to read label key: %d", err);
362362
goto exit;
363363
}
364-
unsigned vlen = MIN(lbl->value.len, CUSTOM_LABEL_MAX_VAL_LEN - 1);
364+
unsigned vlen = MIN(lbl->value.len, CUSTOM_LABEL_MAX_VAL_LEN);
365365
if ((err = bpf_probe_read_user(out_lbl->val, vlen, (void *)lbl->value.buf))) {
366366
increment_metric(metricID_UnwindNativeCustomLabelsErrReadValue);
367367
DEBUG_PRINT("cl: failed to read label value: %d", err);

support/ebpf/tracemgmt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ static inline EBPF_INLINE PerCPURecord *get_pristine_per_cpu_record()
258258
trace->apm_transaction_id.as_int = 0;
259259

260260
trace->custom_labels.len = 0;
261-
u64 *labels_space = (u64 *)&trace->custom_labels.labels;
262-
// I'm not sure this is necessary since we only increment len after
263-
// we successfully write the label.
261+
_Static_assert(sizeof(CustomLabel) % 8 == 0, "CustomLabel size must be a multiple of 8 bytes.");
262+
u64 *labels_space = (u64 *)&trace->custom_labels.labels;
264263
UNROLL for (int i = 0; i < sizeof(CustomLabel) * MAX_CUSTOM_LABELS / 8; i++)
265264
{
266265
labels_space[i] = 0;

support/ebpf/tracer.ebpf.amd64

1.01 KB
Binary file not shown.

support/ebpf/tracer.ebpf.arm64

1.02 KB
Binary file not shown.

support/ebpf/types.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,12 @@ typedef struct __attribute__((packed)) ApmCorrelationBuf {
600600
ApmSpanID transaction_id;
601601
} ApmCorrelationBuf;
602602

603-
#define CUSTOM_LABEL_MAX_KEY_LEN COMM_LEN
604-
// Big enough to hold UUIDs, etc.
605-
#define CUSTOM_LABEL_MAX_VAL_LEN 48
603+
#define CUSTOM_LABEL_MAX_KEY_LEN 25
604+
#define CUSTOM_LABEL_MAX_VAL_LEN 53
606605

607606
typedef struct CustomLabel {
608-
u8 key[CUSTOM_LABEL_MAX_KEY_LEN];
609-
u8 val[CUSTOM_LABEL_MAX_VAL_LEN];
607+
u8 key[CUSTOM_LABEL_MAX_KEY_LEN + 1];
608+
u8 val[CUSTOM_LABEL_MAX_VAL_LEN + 1];
610609
} CustomLabel;
611610

612611
typedef struct NativeCustomLabelsString {

support/types.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)