-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event logger type and function to set event context for writer (#…
…5937) * add event logger type * fix import cycle and tests
- Loading branch information
1 parent
3864896
commit f30fcc0
Showing
6 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2021 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v2 | ||
|
||
import ( | ||
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" | ||
) | ||
|
||
type Config interface { | ||
GetKubeContext() string | ||
AutoBuild() bool | ||
AutoDeploy() bool | ||
AutoSync() bool | ||
GetPipelines() []latestV1.Pipeline | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright 2021 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" | ||
proto "github.com/GoogleContainerTools/skaffold/proto/v2" | ||
) | ||
|
||
type logger struct { | ||
Phase constants.Phase | ||
SubtaskID string | ||
Origin string | ||
} | ||
|
||
func NewLogger(phase constants.Phase, subtaskID, origin string) io.Writer { | ||
return logger{ | ||
Phase: phase, | ||
SubtaskID: subtaskID, | ||
Origin: origin, | ||
} | ||
} | ||
|
||
func (l logger) Write(p []byte) (int, error) { | ||
handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{ | ||
TaskId: fmt.Sprintf("%s-%d", l.Phase, handler.iteration), | ||
SubtaskId: l.SubtaskID, | ||
Origin: l.Origin, | ||
Level: 0, | ||
Message: string(p), | ||
}) | ||
|
||
return len(p), nil | ||
} | ||
|
||
func (ev *eventHandler) handleSkaffoldLogEvent(e *proto.SkaffoldLogEvent) { | ||
ev.handle(&proto.Event{ | ||
EventType: &proto.Event_SkaffoldLogEvent{ | ||
SkaffoldLogEvent: e, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2021 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v2 | ||
|
||
import ( | ||
"testing" | ||
|
||
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1" | ||
"github.com/GoogleContainerTools/skaffold/proto/enums" | ||
proto "github.com/GoogleContainerTools/skaffold/proto/v2" | ||
) | ||
|
||
func TestHandleSkaffoldLogEvent(t *testing.T) { | ||
testHandler := newHandler() | ||
testHandler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test")) | ||
|
||
messages := []string{ | ||
"hi!", | ||
"how's it going", | ||
"hope you're well", | ||
"this is a skaffold test", | ||
} | ||
|
||
// ensure that messages sent through the SkaffoldLog function are populating the event log | ||
for _, message := range messages { | ||
testHandler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{ | ||
TaskId: "Test-0", | ||
SubtaskId: "1", | ||
Origin: "skaffold-test", | ||
Level: enums.LogLevel_INFO, | ||
Message: message, | ||
}) | ||
} | ||
wait(t, func() bool { | ||
testHandler.logLock.Lock() | ||
logLen := len(testHandler.eventLog) | ||
testHandler.logLock.Unlock() | ||
return logLen == len(messages) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters