Skip to content

Fix reading api-address from config file in container#874

Merged
mmatczuk merged 9 commits intomainfrom
mmt/fix_docker_api_address
Aug 5, 2024
Merged

Fix reading api-address from config file in container#874
mmatczuk merged 9 commits intomainfrom
mmt/fix_docker_api_address

Conversation

@mmatczuk
Copy link
Contributor

This patchset implements checking readiness over a Unix socket.
Unnecessary API servers in e2e tests are removed.
The ready command implementation is extended and improved for better reuse.

Fixes #873

@mmatczuk mmatczuk requested a review from Choraden as a code owner July 31, 2024 13:47

FROM ${BASE_IMAGE}

ENV PLATFORM=container
Copy link
Contributor

Choose a reason for hiding this comment

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

How about FORWARDER_PLATFORM? Something to make it difficult to overwrite.

Copy link
Contributor Author

@mmatczuk mmatczuk Aug 1, 2024

Choose a reason for hiding this comment

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

I don't know, the FORWARDER_PLATFORM does not make much sense to me.

We have two situations:

  • The PLATFORM env var gets overwritten by hand when running container - for that we could log warning in the readiness check.
  • Our container behavior kicking in in another setting due to presence of the env var - here I think we are good since we must match both key and value (container)

Let me add some more logging instead.

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 considered adding sth like this

	if p := os.Getenv("PLATFORM"); p != "" {
		if  p == "container" {
			c.apiAddr = "unix:" + cfg.APIUnixSocket
		} else {
			fmt.Fprintf(os.Stderr, "unexpected PLATFORM environment variable: %q\n", p)
		}
	}

But I guess it's not really useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ugly^

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm exaggerating, why would somebody add PLATFORM variable to forwarder container.

s.Close()
}()

return s.Serve(l)
Copy link
Contributor

Choose a reason for hiding this comment

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

It returns an error on server close

^C2024/08/01 08:12:27.518332 [ERROR] fatal error exiting: http: Server closed
exit status 1

"time"
)

func ServeUnixSocket(ctx context.Context, h http.Handler, socketPath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

May we add some logging here?

Copy link
Contributor Author

@mmatczuk mmatczuk Aug 1, 2024

Choose a reason for hiding this comment

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

Any logging should go in handler as this is a helper function.

@mmatczuk mmatczuk force-pushed the mmt/fix_docker_api_address branch from f6db10e to f3677ec Compare August 1, 2024 09:39
@mmatczuk mmatczuk force-pushed the mmt/fix_docker_api_address branch from f3677ec to ee6be19 Compare August 1, 2024 10:28
Copy link
Contributor

@Choraden Choraden left a comment

Choose a reason for hiding this comment

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

LGTM

@mmatczuk mmatczuk merged commit 926558a into main Aug 5, 2024
@mmatczuk mmatczuk deleted the mmt/fix_docker_api_address branch August 5, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker: use unix socket for health checks

2 participants