Skip to content

Commit 422fac2

Browse files
committed
add back v1/event_log endpoint for events
1 parent 60ca26e commit 422fac2

File tree

5 files changed

+302
-108
lines changed

5 files changed

+302
-108
lines changed

integration/rpc_test.go

+74-56
Original file line numberDiff line numberDiff line change
@@ -133,70 +133,88 @@ func TestEventLogRPC(t *testing.T) {
133133
}
134134

135135
func TestEventLogHTTP(t *testing.T) {
136-
if testing.Short() {
137-
t.Skip("skipping integration test")
136+
var tests = []struct {
137+
description string
138+
endpoint string
139+
}{
140+
{
141+
description: "/v1/event_log",
142+
endpoint: "/v1/event_log",
143+
},
144+
{
145+
description: "/v1/events",
146+
endpoint: "/v1/events",
147+
},
138148
}
139149

140-
httpAddr := randomPort()
141-
teardown := setupSkaffoldWithArgs(t, "--rpc-http-port", httpAddr)
142-
defer teardown()
143-
time.Sleep(500 * time.Millisecond) // give skaffold time to process all events
144-
145-
httpResponse, err := http.Get(fmt.Sprintf("http://localhost:%s/v1/events", httpAddr))
146-
if err != nil {
147-
t.Fatalf("error connecting to gRPC REST API: %s", err.Error())
148-
}
149-
defer httpResponse.Body.Close()
150+
for _, test := range tests {
151+
t.Run(test.description, func(t *testing.T) {
152+
if testing.Short() {
153+
t.Skip("skipping integration test")
154+
}
150155

151-
numEntries := 0
152-
var logEntries []proto.LogEntry
153-
for {
154-
e := make([]byte, 1024)
155-
l, err := httpResponse.Body.Read(e)
156-
if err != nil {
157-
t.Errorf("error reading body from http response: %s", err.Error())
158-
}
159-
e = e[0:l] // remove empty bytes from slice
156+
httpAddr := randomPort()
157+
teardown := setupSkaffoldWithArgs(t, "--rpc-http-port", httpAddr)
158+
defer teardown()
159+
time.Sleep(500 * time.Millisecond) // give skaffold time to process all events
160160

161-
// sometimes reads can encompass multiple log entries, since Read() doesn't count newlines as EOF.
162-
readEntries := strings.Split(string(e), "\n")
163-
for _, entryStr := range readEntries {
164-
if entryStr == "" {
165-
continue
161+
httpResponse, err := http.Get(fmt.Sprintf("http://localhost:%s%s", httpAddr, test.endpoint))
162+
if err != nil {
163+
t.Fatalf("error connecting to gRPC REST API: %s", err.Error())
166164
}
167-
var entry proto.LogEntry
168-
// the HTTP wrapper sticks the proto messages into a map of "result" -> message.
169-
// attempting to JSON unmarshal drops necessary proto information, so we just manually
170-
// strip the string off the response and unmarshal directly to the proto message
171-
entryStr = strings.Replace(entryStr, "{\"result\":", "", 1)
172-
entryStr = entryStr[:len(entryStr)-1]
173-
if err := jsonpb.UnmarshalString(entryStr, &entry); err != nil {
174-
t.Errorf("error converting http response to proto: %s", err.Error())
165+
defer httpResponse.Body.Close()
166+
167+
numEntries := 0
168+
var logEntries []proto.LogEntry
169+
for {
170+
e := make([]byte, 1024)
171+
l, err := httpResponse.Body.Read(e)
172+
if err != nil {
173+
t.Errorf("error reading body from http response: %s", err.Error())
174+
}
175+
e = e[0:l] // remove empty bytes from slice
176+
177+
// sometimes reads can encompass multiple log entries, since Read() doesn't count newlines as EOF.
178+
readEntries := strings.Split(string(e), "\n")
179+
for _, entryStr := range readEntries {
180+
if entryStr == "" {
181+
continue
182+
}
183+
var entry proto.LogEntry
184+
// the HTTP wrapper sticks the proto messages into a map of "result" -> message.
185+
// attempting to JSON unmarshal drops necessary proto information, so we just manually
186+
// strip the string off the response and unmarshal directly to the proto message
187+
entryStr = strings.Replace(entryStr, "{\"result\":", "", 1)
188+
entryStr = entryStr[:len(entryStr)-1]
189+
if err := jsonpb.UnmarshalString(entryStr, &entry); err != nil {
190+
t.Errorf("error converting http response to proto: %s", err.Error())
191+
}
192+
numEntries++
193+
logEntries = append(logEntries, entry)
194+
}
195+
if numEntries >= numLogEntries {
196+
break
197+
}
175198
}
176-
numEntries++
177-
logEntries = append(logEntries, entry)
178-
}
179-
if numEntries >= numLogEntries {
180-
break
181-
}
182-
}
183199

184-
metaEntries, buildEntries, deployEntries := 0, 0, 0
185-
for _, entry := range logEntries {
186-
switch entry.Event.GetEventType().(type) {
187-
case *proto.Event_MetaEvent:
188-
metaEntries++
189-
case *proto.Event_BuildEvent:
190-
buildEntries++
191-
case *proto.Event_DeployEvent:
192-
deployEntries++
193-
default:
194-
}
200+
metaEntries, buildEntries, deployEntries := 0, 0, 0
201+
for _, entry := range logEntries {
202+
switch entry.Event.GetEventType().(type) {
203+
case *proto.Event_MetaEvent:
204+
metaEntries++
205+
case *proto.Event_BuildEvent:
206+
buildEntries++
207+
case *proto.Event_DeployEvent:
208+
deployEntries++
209+
default:
210+
}
211+
}
212+
// make sure we have exactly 1 meta entry, 2 deploy entries and 2 build entries
213+
testutil.CheckDeepEqual(t, 1, metaEntries)
214+
testutil.CheckDeepEqual(t, 2, deployEntries)
215+
testutil.CheckDeepEqual(t, 2, buildEntries)
216+
})
195217
}
196-
// make sure we have exactly 1 meta entry, 2 deploy entries and 2 build entries
197-
testutil.CheckDeepEqual(t, 1, metaEntries)
198-
testutil.CheckDeepEqual(t, 2, deployEntries)
199-
testutil.CheckDeepEqual(t, 2, buildEntries)
200218
}
201219

202220
func TestGetStateRPC(t *testing.T) {

pkg/skaffold/server/endpoints.go

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (s *server) EventLog(stream proto.SkaffoldService_EventLogServer) error {
3232
return event.ForEachEvent(stream.Send)
3333
}
3434

35+
func (s *server) Events(stream proto.SkaffoldService_EventsServer) error {
36+
return event.ForEachEvent(stream.Send)
37+
}
38+
3539
func (s *server) Handle(ctx context.Context, e *proto.Event) (*empty.Empty, error) {
3640
event.Handle(e)
3741
return &empty.Empty{}, nil

0 commit comments

Comments
 (0)