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

frontegg-mock: initial commit #23176

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Conversation

maddyblue
Copy link
Contributor

Add a frontegg mock server binary. Needed for testdrive and cloud testing.

Motivation

  • This PR adds a feature that has not yet been specified.

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • This PR includes the following user-facing behavior changes:
    • n/a

@maddyblue maddyblue requested a review from a team as a code owner November 14, 2023 09:37
@maddyblue
Copy link
Contributor Author

@philip-stoev I've sketched out some parts of a frontegg service. I'm not sure how to handle certificate plumbing because I think the test certs service will need to start first, but I need the arguments when making the other services? There must be a correct way to do this. Are you able to take over the python here?

Copy link
Member

@ParkMyCar ParkMyCar left a comment

Choose a reason for hiding this comment

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

Nice!

See the comment about spawning a separate runtime. I have a local branch which largely refactors our test helpers to no longer spawn their own runtimes, so feel free to merge as-is and I can do the refactoring


pub struct FronteggMockServer {
pub url: String,
pub refreshes: Arc<Mutex<u64>>,
Copy link
Member

Choose a reason for hiding this comment

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

any reason to use Mutex<u64> instead of an AtomicU64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. This was copied over from the previous location. If I remember I'll change it.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

auth_requests: Arc::clone(&auth_requests),
};

let runtime = Arc::new(Runtime::new()?);
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised this works! In main.rs we're also creating a runtime, e.g. #[tokio::main], and we create a runtime here. I thought this would have panicked with "creating a runtime within a runtime".

If possible I would prefer fn start(...) to not spawn its own runtime and instead return the server future, e.g.:

pub fn start(...) -> Result<(FronteggMockServer, BoxFuture<'static, ()>), _> { ... }

This allows us to be more flexible with how FronteggMockServer is used. For example, in main.rs we can create our own runtime, but for our integration tests we can spawn the returned future on the test runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might not work, but I recall being able to start the binary and it ran. Yes, doing what you describe would be best. I'd definitely prefer to do that refactor in a followup, as this was copied over from existing code.

Copy link
Member

Choose a reason for hiding this comment

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

Sweet, sounds good to me!

@maddyblue maddyblue requested a review from a team November 15, 2023 01:59
@philip-stoev philip-stoev requested review from philip-stoev and removed request for a team November 15, 2023 08:15
@maddyblue
Copy link
Contributor Author

Finally got this working in mzcompose. That was much more than I expected. @philip-stoev can you re-review? I ran out of time today to add more tests. I'll work on those soon.

@maddyblue maddyblue force-pushed the frontegg-mock branch 2 times, most recently from db58c40 to dc7a576 Compare November 17, 2023 07:11
user=user,
password=password,
port=port,
ssl_context=ssl_context,
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'm worried this will break all other callers that have ssl disabled. Am waiting for tests to see.

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 indeed caused problems; changed to plumb down the ssl context.

@maddyblue maddyblue force-pushed the frontegg-mock branch 3 times, most recently from 6aea2b0 to 1e425c9 Compare November 20, 2023 20:44
Copy link
Member

@benesch benesch left a comment

Choose a reason for hiding this comment

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

Dropped in some comments about calling this frontegg-mock consistently! I think that will reduce confusion.

&& groupadd --system --gid=999 materialize \
&& useradd --system --gid=999 --uid=999 --create-home materialize

COPY mz-frontegg-mock /usr/local/bin/frontegg
Copy link
Member

Choose a reason for hiding this comment

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

Why are we changing the binary name here? If it's mz-frontegg-mock in the repo, just stick with mz-frontegg-mock in the Docker image?

from materialize.ui import UIError


class Frontegg(Service):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class Frontegg(Service):
class FronteggMock(Service):

users,
"--roles",
roles,
]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you want to be overriding the entrypoint here? Just build up a command instead, and use the default entrypoint. Otherwise you'll lose tini.

}
config: ServiceConfig = {
"mzbuild": mzbuild,
"entrypoint": entrypoint,
Copy link
Member

Choose a reason for hiding this comment

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

See below comment about entrypoint vs command.

# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

name: frontegg
Copy link
Member

Choose a reason for hiding this comment

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

I think calling this frontegg-mock would be less confusing. Also matches the binary name that way!

Suggested change
name: frontegg
name: frontegg-mock

elif encoding_key_file:
entrypoint += ["--encoding-key-file", encoding_key_file]
else:
raise UIError("frontegg service must specify encoding-key[-file]")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise UIError("frontegg service must specify encoding-key[-file]")
raise UIError("FronteggMock service must specify encoding-key[-file]")

@@ -135,7 +135,7 @@ create_cert() {
-passout pass:$SSL_SECRET
}

for i in materialized producer postgres certuser
for i in materialized producer postgres certuser balancerd frontegg
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for i in materialized producer postgres certuser balancerd frontegg
for i in materialized producer postgres certuser balancerd frontegg-mock

Comment on lines 26 to 27
name: str = "frontegg",
mzbuild: str = "frontegg",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: str = "frontegg",
mzbuild: str = "frontegg",
name: str = "frontegg-mock",
mzbuild: str = "frontegg-mock",

Add a frontegg mock server.
@maddyblue
Copy link
Contributor Author

Renamed everything to frontegg-mock.

Copy link
Contributor

@def- def- left a comment

Choose a reason for hiding this comment

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

Generally seems good to me, thanks for the additional testing! I want to check coverage too (https://buildkite.com/materialize/coverage/builds/321) but ran into some issues, so don't let that be a blocker.

&& TZ=UTC DEBIAN_FRONTEND=noninteractive apt-get -qy install \
ca-certificates \
tini \
&& groupadd --system --gid=999 materialize \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to specify gid and uid here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea, I cargo culted from other dockerfiles.

config: ServiceConfig = {
"mzbuild": mzbuild,
"command": command,
"ports": [6875, 6876, 6877, 6878],
Copy link
Contributor

Choose a reason for hiding this comment

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

MZ_BALANCER_SQL/HTTP_LISTEN_ADDR ports are 6880/6881 though. Do we not want to expose them?
Edit: seen later, those are exposed in environmentd.

test/balancerd/mzcompose.py Show resolved Hide resolved
@maddyblue maddyblue merged commit 623134a into MaterializeInc:main Nov 21, 2023
75 of 76 checks passed
@maddyblue maddyblue deleted the frontegg-mock branch November 21, 2023 21:34
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.

5 participants