Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Logger inside Deployer #5809

Merged
merged 2 commits into from
May 11, 2021
Merged

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented May 10, 2021

This change embeds the Logger object's responsibilities inside of the Deployer. As "logging" can really be interpreted as "retrieving information from deployed resources", any implementation of a Logger is implicitly tied to an implementation of a Deployer in Skaffold. To pave the way for future implementations of a Deployer that are not centered around Kubernetes, we need to delegate logging responsibilities to the Deployer.

A slightly modified interface for Logger is introduced:

type Logger interface {
	StartLogger(context.Context, io.Writer, []string) error

	StopLogger()

	Mute()

	Unmute()

	SetSince(time.Time)

	RegisterBuildArtifacts([]graph.Artifact)
}

such that the logging-specific actions are more clearly identified when present on the Deployer. One additional method is added, RegisterBuildArtifacts, which allows newly-built artifacts to be added to a pre-existing Logger.

This interface is then embedded into the Deployer interface:

type Deployer interface {
	log.Logger

       ...
}

to ensure that every implementation of Deployer in Skaffold also provides an implementation for Logger.

All existing implementations of Deployer in Skaffold are Kubernetes-centric, and have been retrofitted to use the kubernetes.LogAggregator as their implementation of Logger. in the future, any new Kubernetes-centric Deployer implementations can reuse this Logger, but any new Deployer implementations that use a non-Kubernetes platform (e.g. docker) will need to implement a new Logger.

cc #5813

@nkubala nkubala requested review from yuwenma and a team as code owners May 10, 2021 18:22
@nkubala nkubala requested a review from gsquared94 May 10, 2021 18:22
@google-cla google-cla bot added the cla: yes label May 10, 2021

podSelectors := kubernetes.NewImageList()

logger := getLogger(runCtx, kubectlCLI, podSelectors)
Copy link
Contributor

@gsquared94 gsquared94 May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rather instantiate a LoggerProvider that can instantiate the right Logger in the corresponding Deployer? All the NewDeployer methods can take the LoggerProvider instead. This could map pretty well with a docker.NewDeployer(_, _, loggerProvider) (for the upcoming docker deployer) without any more changes to this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoggerProvider can maintain a singleton instance of a KubernetesLogger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea a lot, I definitely planned on abstracting away the logging implementation from the getLogger() method, but your idea of a provider is much better than a big switch statement. I also want to move all of the get*() methods out of new.go (since this file is getting huge). WDYT about doing this in a follow up PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

if !r.runCtx.Tail() {
return nil
}
type Logger interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does this conflict with the application Logger interfaces? Should we call it DeployLogger or ResourceLogger or something?

Copy link
Contributor

@gsquared94 gsquared94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please address #5809 (comment) in a follow up PR.

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #5809 (bcfbd89) into master (8efc9ef) will decrease coverage by 0.05%.
The diff coverage is 78.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5809      +/-   ##
==========================================
- Coverage   71.00%   70.95%   -0.06%     
==========================================
  Files         438      439       +1     
  Lines       16497    16521      +24     
==========================================
+ Hits        11714    11722       +8     
- Misses       3921     3935      +14     
- Partials      862      864       +2     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/apply.go 25.00% <0.00%> (ø)
cmd/skaffold/app/cmd/delete.go 57.14% <0.00%> (ø)
cmd/skaffold/app/cmd/deploy.go 56.52% <0.00%> (ø)
cmd/skaffold/app/cmd/filter.go 25.58% <0.00%> (ø)
cmd/skaffold/app/cmd/find_configs.go 48.48% <0.00%> (ø)
cmd/skaffold/app/cmd/generate_pipeline.go 61.53% <0.00%> (ø)
cmd/skaffold/app/cmd/render.go 40.74% <0.00%> (ø)
cmd/skaffold/app/cmd/runner.go 58.49% <0.00%> (ø)
cmd/skaffold/app/cmd/test.go 46.66% <0.00%> (ø)
cmd/skaffold/app/cmd/util.go 77.77% <ø> (ø)
... and 136 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d05e94...bcfbd89. Read the comment docs.

@nkubala nkubala enabled auto-merge (squash) May 11, 2021 19:26
@nkubala nkubala merged commit cbb0545 into GoogleContainerTools:master May 11, 2021
@nkubala nkubala deleted the log-refactor branch May 11, 2021 19:59
gsquared94 added a commit to gsquared94/skaffold that referenced this pull request May 17, 2021
@gsquared94 gsquared94 mentioned this pull request May 17, 2021
tejal29 pushed a commit that referenced this pull request May 17, 2021
* Revert "Embed PortForwarder in Deployer, rename to ResourcePreviewer (#5826)"

This reverts commit 6d66d85.

* Revert "Embed Logger inside Deployer (#5809)"

This reverts commit cbb0545.

* commit foo file
@nkubala nkubala restored the log-refactor branch May 25, 2021 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants