[go: nahoru, domu]

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

✨ Introducing examples module #14

Merged
merged 13 commits into from
May 7, 2022
Merged

Conversation

PeterEFinch
Copy link
Contributor

No description provided.

@PeterEFinch PeterEFinch added the enhancement New feature or request label Mar 4, 2022
@PeterEFinch PeterEFinch requested a review from a user March 4, 2022 00:49
Copy link
@ghost ghost left a comment

Choose a reason for hiding this comment

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

Use examples_test.go & Example…(). Then you (and I) can be sure that this example will work now and in future :-)

examples.md Outdated
Comment on lines 50 to 51
// The specifics of gracefully shutting down the service, include the timeout
// and error handling, should be decided by the user.
Copy link

Choose a reason for hiding this comment

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

Kinda. There’s a hard kill-timeout on a pod, though. Think it’s 30sec. by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a general library for managing shutdowns. I want to avoid tying it to certain technologies, e.g. GCloud/Kubernetes, as this would limit its usage. Additionally, if there are multiple shutdown actions it is then amount of time given for each might different.

Copy link

Choose a reason for hiding this comment

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

Yeah, fine. However, I think it would be nice to mention the GKE-specifics in the comments. As this is a company-only library (yet).

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 am still reluctant as my goal is to not tie this to a technology even in a comment.

Copy link

Choose a reason for hiding this comment

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

my goal is to not tie this to a technology even in a comment.

I don’t get it, really:

  1. What’s your intended audience? As this library (currently) resides only internally in our small company, the technology-setup is clear: Kubernetes with containerd/OCI-runtime, i.e. somehow POSIX-compatibility. Therefore I think it makes sense to give some explanation for it. At least in a comment.
  2. The library is tied to the technology-setup above anyway. E.g. a (rather) quick search shows that it would not work even on Windows (see Unable to react to graceful shutdown of (Windows) container moby/moby#25982). To be fair, (only?) part of if fixed quite recently (2020) in Go, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intended audience is the developers at Graphmasters. My approach is more about creating minimal code and independent code (with comments).

Copy link

Choose a reason for hiding this comment

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

“minimal”: agreed and like
“independent”: unrealistic dream (see above)

Actually, independence for a developer in a DevOps-culture means (s)he needs to have, at least a basic, understanding of the underlying technology stack (what historically only operators had). I.e. it would help giving some insights on the underlying technology here to raise independence of the developers ☝🏿

See e.g. this K8s-failure-story (https://k8s.af): Kubernetes' dirty endpoint secret and Ingress — Grace is overrated. That’s a topic we still see on our services, i.e. there’s no good solution found. Means our (Go-)code depends on the infrastructure/technology used.

examples.md Outdated Show resolved Hide resolved
examples.md Outdated
// The server starts listening. It should never encounter an error other
// than the server being closed.
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("server encountered error: %v", err)
Copy link

Choose a reason for hiding this comment

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

Is closing immediately the right thing to do here when using this module? I would say no. It’s contradictory to what safe down means.

Copy link
Contributor Author
@PeterEFinch PeterEFinch Mar 7, 2022

Choose a reason for hiding this comment

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

Safedown allows you the ability to coordinate shutting down across multiple go routines and gracefully in the face of an interrupt (or similar) signal.

What exactly should happen here is unclear and probably a debate for best practices (the primary purpose of this library is to provide functionality not demonstrate best practices).

In this case the graceful shutdown is primarily for the HTTP server. Arguably, if ListenAndServe fails then there is no need to be graceful.

If you can say what you think should happen here and why then I am willing to change it.

Copy link

Choose a reason for hiding this comment

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

I would say an error-log would be the correct thing. You assume that there’s only one server running. But that’s not the case, e.g. most have an extra status-server where it would be really good to serve (error-)metrics esp. in case the main server(s) fail. Other examples are many gRPC-services (one server to public, one cluster-internal).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DominikGM This is a best practices issue. I have seen people log the errors, have fatals and have panics. I know what I would use, I just don't want this place to be a best practices and have to change stuff because what is considered best has changed.

Copy link

Choose a reason for hiding this comment

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

Ok. Then the only reasonable thing you could do is to use a comment like // handle error
Code of a module is often consumed as a best-practice thing. You’re right that it shouldn’t be done like this, but that’s my experience from reality.

Therefore

I have seen people […] have fatals and have panics.

is still wrong. As you have a Fatal() in it, this implicit best-practice isn’t good practice, IMO.

Copy link
Contributor Author
@PeterEFinch PeterEFinch Mar 18, 2022

Choose a reason for hiding this comment

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

@DominikGM I still don't think there is a definitive right way and think that using a fatal is a reasonable choice. Nevertheless, I have changed it to just a log and added a comment because if it had been this way at the start I would be fine with it.

	if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
		// It is up to the user how the error should be handled. This is only 
		// for illustrative purposes.
		log.Printf("server encountered error: %v", err)
	}

Copy link

Choose a reason for hiding this comment

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

With using Fatal(), this would result in a short 502-spike (perhaps for <= 1% calls). Still if you have a sensitive alert on this, you would notice this. See the example mentioned above: #14 (comment)

examples.md Outdated Show resolved Hide resolved
@PeterEFinch
Copy link
Contributor Author

Use examples_test.go & Example…(). Then you (and I) can be sure that this example will work now and in future :-)

@DominikGM I specifically didn't use examples_test.go because:

  1. I don't want ANY dependencies in this library.
  2. Examples are run along side tests and since this main function should never stop the example would cause problems with testing unless we added additional code to send an interrupt signal, which I think would complicate the code.

There is certainly a benefit to writing example tests (and there is already one), however, I think the merits aren't worth it in this situation.

@PeterEFinch
Copy link
Contributor Author

@DominikGM Just a ping for a week of inactivity.

@ghost ghost mentioned this pull request Mar 16, 2022
@PeterEFinch
Copy link
Contributor Author

@DominikGM In my opinion the best thing about this library is that it is simple, it does one thing, and it is independent of pretty much everything. I have tried to get it to a stage where it doesn't need to be touched or actively maintained. It is for this reason that I am opposed to anything which changes this. I know it is a strict convention. It does seem to be working so far.

@ghost ghost mentioned this pull request Mar 18, 2022
@PeterEFinch
Copy link
Contributor Author

This pull request addresses the concern of having a practical example that represents a service, specifically a HTTP service.

I think it is getting to the stage where the benefits of any changes is less than the effort of discussing it. As such, I propose that, unless there are major or significant issues, we move on from this pull request.

If there is additional feedback received that examples are lacking, confusing or lead developers to misunderstandings then we can address it at a future date.

@PeterEFinch
Copy link
Contributor Author

@DominikGM Instead of having the code in a readme, there is now another module just containing examples.

I intend to change the circleci to github actions soon at which stage I will also add a step for building the mains in the examples module. This way we can be sure that the code in the examples module will always build.

@PeterEFinch
Copy link
Contributor Author

I am making the decision as admin and lead maintainer of this library that this pull request is suitable for merging.

@PeterEFinch PeterEFinch changed the title 📝 Adding additional examples ✨ Introducing examples module May 7, 2022
@PeterEFinch PeterEFinch merged commit 4554ae8 into master May 7, 2022
@PeterEFinch PeterEFinch deleted the documentation/more_examples branch May 7, 2022 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant