Skip to content

Commit dc9db68

Browse files
committed
add back v1/event_log endpoint for events
1 parent 26fc7dd commit dc9db68

File tree

5 files changed

+281
-107
lines changed

5 files changed

+281
-107
lines changed

integration/rpc_test.go

+74-56
Original file line numberDiff line numberDiff line change
@@ -133,73 +133,91 @@ 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
if ShouldRunGCPOnlyTests() {
140150
t.Skip("skipping test that is not gcp only")
141151
}
142152

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

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

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

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

205223
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

proto/skaffold.pb.go

+120-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)