Skip to content

Commit 94ba1e9

Browse files
tobixlealambda-tooling+riegithub-advanced-security[bot]
authored
feat: rie private to public automation initial merge (#172)
* Update from upstream - 2026-03-18 * Update from upstream - 2026-03-18 * Update from upstream - 2026-03-18 * Update from upstream - 2026-03-19 * Update from upstream - 2026-03-19 * Potential fix for code scanning alert no. 7: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update from upstream - 2026-03-27 * Update from upstream - 2026-03-30 --------- Co-authored-by: lambda-tooling+rie <lambda-tooling+rie@amazon.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent c0d1a14 commit 94ba1e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1743
-74
lines changed

.github/workflows/integ-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
branches:
66
- develop
77
- main
8-
8+
merge_group:
9+
910
permissions:
1011
contents: read
1112

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Validate PR Branch into Main
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
validate-pr-branch:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check source branch
13+
run: |
14+
SOURCE_BRANCH="${{ github.head_ref }}"
15+
if [[ "$SOURCE_BRANCH" != "develop" ]]; then
16+
echo "Error: Only pull requests from develop branch are allowed into main"
17+
echo "Current source branch ($SOURCE_BRANCH)."
18+
exit 1
19+
fi
20+
echo "Source branch is develop - merge allowed"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
193193
194194
## License
195195
196-
This project is licensed under the Apache-2.0 License.
196+
This project is licensed under the Apache-2.0 License.

internal/lambda-managed-instances/aws-lambda-rie/internal/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ func GetInitRequestMessage(fileUtil utils.FileUtil, args []string) (intmodel.Ini
6161
XrayTracingMode: intmodel.XRayTracingModePassThrough,
6262
CurrentWorkingDir: cwd,
6363
RuntimeBinaryCommand: cmd,
64-
AvailabilityZoneId: "",
65-
AmiId: "",
64+
65+
AvailabilityZoneId: "use1-az1",
66+
AmiId: "",
6667
}, nil
6768
}
6869

internal/lambda-managed-instances/aws-lambda-rie/internal/init_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Test_getInitRequestMessage(t *testing.T) {
6262
XrayTracingMode: intmodel.XRayTracingModePassThrough,
6363
CurrentWorkingDir: "REPLACE",
6464
RuntimeBinaryCommand: []string{"/path/to/bootstrap"},
65-
AvailabilityZoneId: "",
65+
AvailabilityZoneId: "use1-az1",
6666
AmiId: "",
6767
},
6868
},
@@ -116,7 +116,7 @@ func Test_getInitRequestMessage(t *testing.T) {
116116
XrayTracingMode: intmodel.XRayTracingModePassThrough,
117117
CurrentWorkingDir: "/var/task",
118118
RuntimeBinaryCommand: []string{"/custom/bootstrap", "custom_handler"},
119-
AvailabilityZoneId: "",
119+
AvailabilityZoneId: "use1-az1",
120120
AmiId: "",
121121
},
122122
},

internal/lambda-managed-instances/aws-lambda-rie/internal/run.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"os"
1111
"time"
1212

13+
"github.com/google/uuid"
14+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
15+
1316
rieinvoke "github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda-managed-instances/aws-lambda-rie/internal/invoke"
1417
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda-managed-instances/aws-lambda-rie/internal/telemetry"
1518
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda-managed-instances/interop"
@@ -47,8 +50,9 @@ func Run(supv supvmodel.ProcessSupervisor, args []string, fileUtil utils.FileUti
4750
responderFactoryFunc := func(_ context.Context, invokeReq interop.InvokeRequest) invoke.InvokeResponseSender {
4851
return rieinvoke.NewResponder(invokeReq)
4952
}
50-
invokeRouter := invoke.NewInvokeRouter(rapid.MaxIdleRuntimesQueueSize, eventsAPI, responderFactoryFunc, timeout.NewRecentCache())
53+
invokeRouter := invoke.NewInvokeRouter(rapid.RuntimePoolSize, eventsAPI, responderFactoryFunc, timeout.NewRecentCache())
5154

55+
metadataToken := uuid.NewString()
5256
deps := rapid.Dependencies{
5357
EventsAPI: eventsAPI,
5458
LogsEgressAPI: telemetry.NewLogsEgress(telemetryAPIRelay, os.Stdout),
@@ -57,9 +61,10 @@ func Run(supv supvmodel.ProcessSupervisor, args []string, fileUtil utils.FileUti
5761
RuntimeAPIAddrPort: runtimeAPIAddr,
5862
FileUtils: fileUtil,
5963
InvokeRouter: invokeRouter,
64+
MetadataService: lmds.NewService(metadataToken),
6065
}
6166

62-
raptorApp, err := raptor.StartApp(deps, "", noOpLogger{})
67+
raptorApp, err := raptor.StartApp(deps, "", metadataToken, noOpLogger{})
6368
if err != nil {
6469
return nil, nil, nil, fmt.Errorf("could not start runtime api server: %w", err)
6570
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# RIE Telemetry Package
2+
3+
The RIE (Runtime Interface Emulator) telemetry package provides Telemetry API.
4+
5+
## Architecture Overview
6+
7+
```
8+
┌─────────────────┐ ┌─────────────────┐ ┌──────────────────┐
9+
│ EventsAPI │ │ LogsEgress │ │ SubscriptionAPI │
10+
│ │ │ │ │ │
11+
│ • Platform │ │ • Runtime logs │ │ • Subscription │
12+
│ events │ │ • Extension │ │ management │
13+
│ • Lifecycle │ │ logs │ │ • Schema │
14+
│ events │ │ • Log capture │ │ validation │
15+
└─────────┬───────┘ └─────────┬───────┘ └──────────┬───────┘
16+
│ │ │
17+
└──────────────┬───────────────────────────────┘
18+
19+
┌────▼────┐
20+
│ Relay │
21+
│ │
22+
│ Event │
23+
│ Broker │
24+
└────┬────┘
25+
26+
┌──────────────┼──────────────┐
27+
│ │ │
28+
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
29+
│Subscriber │ │Subscriber │ │Subscriber │
30+
│ A │ │ B │ │ C │
31+
└─────┬─────┘ └─────┬─────┘ └─────┬─────┘
32+
│ │ │
33+
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
34+
│TCP Client │ │HTTP Client│ │TCP Client │
35+
└───────────┘ └───────────┘ └───────────┘
36+
```
37+
38+
## Core Components
39+
40+
### 1. EventsAPI (`events_api.go`)
41+
**Responsibility**: Platform event generation and distribution
42+
43+
The EventsAPI serves as the primary interface for generating and broadcasting AWS Lambda platform events. It implements the `EventsAPI` interface and handles various lifecycle events including initialization, invocation, and error reporting.
44+
45+
### 2. LogsEgress (`logs_egress.go`)
46+
**Responsibility**: Log capture and forwarding
47+
48+
The LogsEgress component implements the `StdLogsEgressAPI` interface to capture stdout/stderr from both runtime and extensions, forwarding them to telemetry subscribers while maintaining original console output.
49+
50+
### 3. Relay (`relay.go`)
51+
**Responsibility**: Event broadcasting and subscriber management
52+
53+
The Relay acts as a central event broker, managing subscribers and broadcasting events to all registered telemetry consumers.
54+
55+
### 4. SubscriptionAPI (`subscription_api.go`)
56+
**Responsibility**: Subscription management and validation
57+
58+
The SubscriptionAPI handles telemetry subscription requests, validates them against JSON schemas, and manages the subscription lifecycle.
59+
60+
## Internal Components
61+
62+
### 1. Subscriber (`internal/subscriber.go`)
63+
**Responsibility**: Event batching and delivery
64+
65+
Each subscriber represents a telemetry consumer and manages efficient event delivery through batching and asynchronous processing.
66+
67+
### 2. Client (`internal/client.go`)
68+
**Responsibility**: Protocol-specific event delivery
69+
70+
The client abstraction provides protocol-specific implementations for delivering events to telemetry consumers.
71+
72+
### 3. Batch (`internal/batch.go`)
73+
**Responsibility**: Event collection and timing
74+
75+
The batch component manages collections of events with size and time-based flushing logic.
76+
77+
### 4. Types (`internal/types.go`)
78+
**Responsibility**: Type definitions and constants
79+
80+
Centralized type definitions for protocols, event categories, and configuration structures.
81+
82+
## Event Flow
83+
84+
### 1. Subscription Flow
85+
```
86+
Extension/Agent → SubscriptionAPI → Schema Validation → Subscriber Creation → Relay Registration
87+
```
88+
89+
### 2. Event Flow
90+
```
91+
Event Source → EventsAPI → Relay → Subscribers → Batching → Client
92+
```
93+
94+
### 3. Log Flow
95+
```
96+
Runtime/Extension → LogsEgress → Console Output + Relay → Subscribers → Batching → Client
97+
```

internal/lambda-managed-instances/aws-lambda-rie/internal/telemetry/internal/subscriber_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestSubscriber(t *testing.T) {
2525

2626
agentName := fmt.Sprintf("test-name-%d", rand.Uint32())
2727
sub := NewSubscriber(agentName, map[EventCategory]struct{}{CategoryPlatform: {}}, BufferingConfig{MaxItems: 2, MaxBytes: math.MaxInt, Timeout: math.MaxInt}, client, logsDroppedEventAPI)
28-
time.Sleep(100 * time.Millisecond)
28+
time.Sleep(200 * time.Millisecond)
2929
assert.Equal(t, agentName, sub.AgentName())
3030

3131
sub.Flush(context.Background())
@@ -43,19 +43,23 @@ func TestSubscriber(t *testing.T) {
4343
client.On("send", mock.Anything, mock.Anything).Return(nil)
4444
sub.SendAsync(event, CategoryPlatform)
4545

46+
time.Sleep(100 * time.Millisecond)
47+
4648
require.Eventually(t, func() bool {
4749
return client.AssertNumberOfCalls(t, "send", 1)
48-
}, time.Second, 10*time.Millisecond)
50+
}, 2*time.Second, 10*time.Millisecond)
4951

5052
sub.SendAsync(event, CategoryPlatform)
53+
54+
time.Sleep(100 * time.Millisecond)
5155
assert.Eventually(
5256
t,
5357
func() bool {
5458

5559
sub.Flush(context.Background())
5660
return client.AssertNumberOfCalls(t, "send", 2)
5761
},
58-
time.Second,
62+
2*time.Second,
5963
10*time.Millisecond,
6064
)
6165
}

internal/lambda-managed-instances/aws-lambda-rie/internal/telemetry/logs_egress_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/mock"
1213
"github.com/stretchr/testify/require"
1314

1415
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda-managed-instances/aws-lambda-rie/internal/telemetry/internal"
@@ -53,17 +54,31 @@ func TestLogsEgress(t *testing.T) {
5354
require.NotNil(t, stderr)
5455

5556
line := []byte("test\n")
56-
relay.On("broadcast", "test", tt.expectedCategory, tt.expectedCategory).Twice()
57+
58+
done := make(chan struct{}, 2)
59+
60+
relay.
61+
On("broadcast", "test", tt.expectedCategory, tt.expectedCategory).
62+
Twice().
63+
Run(func(args mock.Arguments) {
64+
done <- struct{}{}
65+
})
66+
5767
n, err := stdout.Write(line)
5868
assert.NoError(t, err)
5969
assert.Len(t, line, n)
6070
n, err = stderr.Write(line)
6171
assert.NoError(t, err)
6272
assert.Len(t, line, n)
6373

64-
assert.Eventually(t, func() bool {
65-
return relay.AssertNumberOfCalls(t, "broadcast", 2)
66-
}, 1*time.Second, 10*time.Millisecond)
74+
for i := 0; i < 2; i++ {
75+
select {
76+
case <-done:
77+
78+
case <-time.After(2 * time.Second):
79+
t.Fatal("timeout waiting for broadcast calls")
80+
}
81+
}
6782
})
6883
}
6984
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda-managed-instances/aws-lambda-rie/run"
8+
)
9+
10+
func main() {
11+
run.Run()
12+
}

0 commit comments

Comments
 (0)