Skip to content

Commit dacd756

Browse files
committed
feat: bump xp-runtime to get step name
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
1 parent ace0ed1 commit dacd756

File tree

4 files changed

+61
-54
lines changed

4 files changed

+61
-54
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ go 1.24.9
44

55
require (
66
github.com/alecthomas/kong v1.10.0
7-
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260127103424-627736f1b9f1
7+
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260130110818-b375c81880a3
88
github.com/go-logr/zapr v1.3.0
9+
github.com/google/go-cmp v0.7.0
910
go.uber.org/zap v1.27.1
1011
google.golang.org/grpc v1.75.1
1112
google.golang.org/protobuf v1.36.11

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/alecthomas/kong v1.10.0 h1:8K4rGDpT7Iu+jEXCIJUeKqvpwZHbsFRoebLbnzlmrp
44
github.com/alecthomas/kong v1.10.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
55
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
66
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
7-
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260127103424-627736f1b9f1 h1:y5C/HJq9SXLYynEh4ZK6Tf7tDrsJNS+a5Ysjg9Eyc2I=
8-
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260127103424-627736f1b9f1/go.mod h1:WVVus9FBbAVjAmFxrOGDdZBFuUv9TqR916JmVl3PVRk=
7+
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260130110818-b375c81880a3 h1:MJuAjQSIhOhqFB//iEOqeQtFRA85QHQjJODKWRkFbCg=
8+
github.com/crossplane/crossplane-runtime/v2 v2.2.0-rc.0.0.20260130110818-b375c81880a3/go.mod h1:WVVus9FBbAVjAmFxrOGDdZBFuUv9TqR916JmVl3PVRk=
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1010
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1111
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=

server/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ func (i *Inspector) logText(eventType string, meta *pipelinev1alpha1.StepMeta, p
148148
_, _ = fmt.Fprintf(i.out, " XR NS: %s\n", ns)
149149
}
150150
_, _ = fmt.Fprintf(i.out, " Composition: %s\n", meta.GetCompositionName())
151-
_, _ = fmt.Fprintf(i.out, " Function: %s (step %d, iteration %d)\n", meta.GetFunctionName(), meta.GetStepIndex(), meta.GetIteration())
151+
_, _ = fmt.Fprintf(i.out, " Step: %s (index %d, iteration %d)\n", meta.GetStepName(), meta.GetStepIndex(), meta.GetIteration())
152+
_, _ = fmt.Fprintf(i.out, " Function: %s\n", meta.GetFunctionName())
152153
_, _ = fmt.Fprintf(i.out, " Trace ID: %s\n", meta.GetTraceId())
153154
_, _ = fmt.Fprintf(i.out, " Span ID: %s\n", meta.GetSpanId())
154155
_, _ = fmt.Fprintf(i.out, " Timestamp: %s\n", meta.GetTimestamp().AsTime().Format("2006-01-02T15:04:05.000Z07:00"))

server/server_test.go

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/google/go-cmp/cmp"
2627
"google.golang.org/protobuf/types/known/timestamppb"
2728

2829
pipelinev1alpha1 "github.com/crossplane/crossplane-runtime/v2/apis/pipelineinspector/proto/v1alpha1"
@@ -144,6 +145,7 @@ func TestEmitRequest_Text(t *testing.T) {
144145
CompositeResourceUid: "uid-123",
145146
CompositeResourceNamespace: "my-namespace",
146147
CompositionName: "my-composition",
148+
StepName: "my-step",
147149
FunctionName: "my-function",
148150
TraceId: "trace-abc",
149151
SpanId: "span-def",
@@ -159,44 +161,23 @@ func TestEmitRequest_Text(t *testing.T) {
159161

160162
_, _ = inspector.EmitRequest(context.Background(), req)
161163

162-
output := buf.String()
163-
164-
// Verify header.
165-
if !strings.Contains(output, "=== REQUEST ===") {
166-
t.Errorf("expected REQUEST header, got: %s", output)
167-
}
168-
169-
// Verify XR info.
170-
if !strings.Contains(output, "XR: example.org/v1/XDatabase (my-xr)") {
171-
t.Errorf("expected XR info in output, got: %s", output)
172-
}
173-
174-
// Verify UID is included.
175-
if !strings.Contains(output, "XR UID: uid-123") {
176-
t.Errorf("expected XR UID in output, got: %s", output)
177-
}
178-
179-
// Verify namespace is included.
180-
if !strings.Contains(output, "XR NS: my-namespace") {
181-
t.Errorf("expected XR namespace in output, got: %s", output)
182-
}
164+
want := `=== REQUEST ===
165+
XR: example.org/v1/XDatabase (my-xr)
166+
XR UID: uid-123
167+
XR NS: my-namespace
168+
Composition: my-composition
169+
Step: my-step (index 1, iteration 2)
170+
Function: my-function
171+
Trace ID: trace-abc
172+
Span ID: span-def
173+
Timestamp: 2026-01-15T10:30:00.000Z
174+
Payload:
175+
apiVersion: apiextensions.crossplane.io/v1
183176
184-
// Verify composition name.
185-
if !strings.Contains(output, "Composition: my-composition") {
186-
t.Errorf("expected composition name in output, got: %s", output)
187-
}
188-
189-
// Verify function info.
190-
if !strings.Contains(output, "Function: my-function (step 1, iteration 2)") {
191-
t.Errorf("expected function info in output, got: %s", output)
192-
}
193177
194-
// Verify trace and span IDs.
195-
if !strings.Contains(output, "Trace ID: trace-abc") {
196-
t.Errorf("expected trace ID in output, got: %s", output)
197-
}
198-
if !strings.Contains(output, "Span ID: span-def") {
199-
t.Errorf("expected span ID in output, got: %s", output)
178+
`
179+
if diff := cmp.Diff(want, buf.String()); diff != "" {
180+
t.Errorf("EmitRequest text output mismatch (-want +got):\n%s", diff)
200181
}
201182
}
202183

@@ -212,8 +193,9 @@ func TestEmitRequest_Text_NoNamespace(t *testing.T) {
212193
CompositeResourceUid: "uid-456",
213194
CompositeResourceNamespace: "", // Empty for cluster-scoped.
214195
CompositionName: "cluster-composition",
196+
StepName: "my-step",
215197
FunctionName: "my-function",
216-
Timestamp: timestamppb.New(time.Now()),
198+
Timestamp: timestamppb.New(time.Date(2026, 1, 15, 10, 30, 0, 0, time.UTC)),
217199
}
218200

219201
req := &pipelinev1alpha1.EmitRequestRequest{
@@ -223,11 +205,20 @@ func TestEmitRequest_Text_NoNamespace(t *testing.T) {
223205

224206
_, _ = inspector.EmitRequest(context.Background(), req)
225207

226-
output := buf.String()
227-
228-
// Verify namespace line is NOT included for cluster-scoped resources.
229-
if strings.Contains(output, "XR NS:") {
230-
t.Errorf("expected no XR NS line for cluster-scoped resource, got: %s", output)
208+
want := "=== REQUEST ===\n" +
209+
" XR: example.org/v1/XClusterDatabase (my-cluster-xr)\n" +
210+
" XR UID: uid-456\n" +
211+
" Composition: cluster-composition\n" +
212+
" Step: my-step (index 0, iteration 0)\n" +
213+
" Function: my-function\n" +
214+
" Trace ID: \n" +
215+
" Span ID: \n" +
216+
" Timestamp: 2026-01-15T10:30:00.000Z\n" +
217+
" Payload:\n" +
218+
" {}\n" +
219+
"\n\n"
220+
if diff := cmp.Diff(want, buf.String()); diff != "" {
221+
t.Errorf("EmitRequest text output mismatch (-want +got):\n%s", diff)
231222
}
232223
}
233224

@@ -236,8 +227,12 @@ func TestEmitResponse_Text_WithError(t *testing.T) {
236227
inspector := NewInspector("text", WithOutput(&buf))
237228

238229
meta := &pipelinev1alpha1.StepMeta{
239-
FunctionName: "failing-function",
240-
Timestamp: timestamppb.New(time.Now()),
230+
CompositeResourceApiVersion: "example.org/v1",
231+
CompositeResourceKind: "XDatabase",
232+
CompositeResourceName: "my-xr",
233+
StepName: "failing-step",
234+
FunctionName: "failing-function",
235+
Timestamp: timestamppb.New(time.Date(2026, 1, 15, 10, 30, 0, 0, time.UTC)),
241236
}
242237

243238
req := &pipelinev1alpha1.EmitResponseRequest{
@@ -248,9 +243,19 @@ func TestEmitResponse_Text_WithError(t *testing.T) {
248243

249244
_, _ = inspector.EmitResponse(context.Background(), req)
250245

251-
output := buf.String()
252-
if !strings.Contains(output, "Error: something went wrong") {
253-
t.Errorf("expected error in output, got: %s", output)
246+
want := "=== RESPONSE ===\n" +
247+
" XR: example.org/v1/XDatabase (my-xr)\n" +
248+
" XR UID: \n" +
249+
" Composition: \n" +
250+
" Step: failing-step (index 0, iteration 0)\n" +
251+
" Function: failing-function\n" +
252+
" Trace ID: \n" +
253+
" Span ID: \n" +
254+
" Timestamp: 2026-01-15T10:30:00.000Z\n" +
255+
" Error: something went wrong\n" +
256+
"\n"
257+
if diff := cmp.Diff(want, buf.String()); diff != "" {
258+
t.Errorf("EmitResponse text output mismatch (-want +got):\n%s", diff)
254259
}
255260
}
256261

@@ -351,9 +356,9 @@ func TestIndentLines(t *testing.T) {
351356

352357
for _, tt := range tests {
353358
t.Run(tt.name, func(t *testing.T) {
354-
result := indentLines(tt.input, tt.prefix)
355-
if result != tt.expected {
356-
t.Errorf("indentLines(%q, %q) = %q, want %q", tt.input, tt.prefix, result, tt.expected)
359+
got := indentLines(tt.input, tt.prefix)
360+
if diff := cmp.Diff(tt.expected, got); diff != "" {
361+
t.Errorf("indentLines(%q, %q) mismatch (-want +got):\n%s", tt.input, tt.prefix, diff)
357362
}
358363
})
359364
}

0 commit comments

Comments
 (0)