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

Convert GraphQL v2 to Quarkus #1980

Merged
merged 32 commits into from
Sep 2, 2022
Merged

Convert GraphQL v2 to Quarkus #1980

merged 32 commits into from
Sep 2, 2022

Conversation

olim7t
Copy link
Collaborator

@olim7t olim7t commented Jul 15, 2022

Main changes:

  • GraphqlResourceBase and subclasses: use injection to pass the bridge and GraphqlCache, adapt multipart handling code for Quarkus.
  • GraphqlCache: use Quarkus config for enableDefaultKeyspace

Everything else is pretty much a copy-paste of the existing sgv2-graphqlapi, with a few changes to the imports. Note that fetcher implementations still rely on the synchronous methods of StargateBridgeClient; with the async/reactive bridge it would now be possible to make all fetchers async, but I consider this beyond the scope of this PR, see #421.

TODO:

  • find a way to add stargate.graphql.enable-playground to the config (how do we condition the inclusion of a REST resource at runtime?)
  • adapt (move?) the integration tests in testing
  • remove the original sgv2-graphqlapi at the root of the repo
  • handle OVERLOADED error (see GraphqlResourceBase.executeAsync)

@olim7t olim7t force-pushed the sgv2-graphqlapi-quarkus branch 2 times, most recently from 5f2aac7 to feddbc0 Compare July 22, 2022 17:31
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

public abstract class GraphqlIntegrationTest {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For now, this relies on inheritance, which is a bit underwhelming. Requests are executed through the bridge.

I would prefer to port CqlSessionExtension from the v1 codebase, but it's not yet clear to me if/how a Junit extension can interact with a Quarkus test extension.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should be able to have the CqlSessionExtension here as well, that communicates over the bridge or maybe even directly over the CQL port.. For this to happen, we need to expose host and port of the target CQL port in the integration tests.. Then you can use Cassandra driver to push needed cql statements..

I might be working on this while you are on holiday.. Let's sync once you are back..

@olim7t olim7t force-pushed the sgv2-graphqlapi-quarkus branch from 518cb1c to 908e72c Compare August 11, 2022 00:59
@olim7t olim7t marked this pull request as ready for review August 12, 2022 17:50
@olim7t olim7t requested a review from a team as a code owner August 12, 2022 17:50
@olim7t olim7t force-pushed the sgv2-graphqlapi-quarkus branch from 79ada51 to 688e18e Compare August 12, 2022 21:28
@olim7t olim7t force-pushed the sgv2-graphqlapi-quarkus branch from e7836c0 to 5d23b3d Compare August 22, 2022 22:52
Copy link
Contributor

@ivansenic ivansenic left a comment

Choose a reason for hiding this comment

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

I tried my best to give as much feedback as possible.. I think we should bring to the merging state as soon as possible and then have tickets for future improvements..

General notes:

  • the api CI workflow was not extended to include sgv2-graphql for the integration tests.. If you disable fixed token in the int-tests, then you can to add your service to be docker-based tested
  • can we get the set of tickets for improvements, for example removing StargateBridgeClient, async fetchers if possible and going into reactive programming model, etc (you know better)
  • nit: banner setup is missing

returns raw JSON responses. See [GraphqlClient] and its subclasses.

If you add new tests, please favor the lightweight approach.
<!-- TODO integration tests -->
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to introduce a similar guides for building the app, building the docker, int tests, etc as we do for the docs-api.. I guess it would be more a copy & paste.. I think the readme should provide all the information possible.. What about configuration guide as in the docs api?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of copy-pasting, maybe it should move to the top-level readme?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me, we can even move this to a separate task to speed merging this in. It's low priority anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that we should prioritize merging to the v.2.0.0 branch. That will make it easier to work on the documentation across all 3 of the APIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created #2052.

Comment on lines +240 to 243
return DEFAULT_PARAMETERS.toBuilder()
.setConsistency(consistencyLevel)
.setSerialConsistency(serialConsistencyLevel)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be read from the configuration now? at least the default values? I am talking about consistency:

### Queries configuration
*Configuration mapping for the query properties, defined by [QueriesConfig.java](src/main/java/io/stargate/sgv2/api/common/config/QueriesConfig.java).*
| Property | Type | Default | Description |
|-----------------------------------------------|----------|----------------|----------------------------------------------------------------------------------|
| `stargate.queries.consistency.schema-changes` | `String` | `LOCAL_QUORUM` | Consistency level to use for C* queries that are performing the schema changes. |
| `stargate.queries.consistency.writes` | `String` | `LOCAL_QUORUM` | Consistency level to use for C* queries that are inserting or updating the data. |
| `stargate.queries.consistency.reads` | `String` | `LOCAL_QUORUM` | Consistency level to use for C* queries that are reading the data. |

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Follow-up ticket: #2053

* <p>Subclasses must be annotated with {@link io.quarkus.test.junit.QuarkusIntegrationTest}.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class CqlEnabledIntegrationTestBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

cool stuff, can be used in docs api as well.. Do you think in future having CqlSession like stuff as annotation would make sense? Or this is enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This can probably be turned into a test resource, now that the contact point info is passed as system properties. The only requirement is that StargateTestResource needs to execute first, do you know if there is a way to enforce a reliable order?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok apparently there is QuarkusTestResourceLifecycleManager.order(), I'll give it a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrmm actually a test resource might not be the best fit:

These resources are started before the first test is run, and are closed at the end of the test suite.

There's no class-level lifecycle that would allow us to create the session and a dedicated keyspace before each test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I was more thinking about Junit5 extension..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Follow-up ticket: #2054

docker-compose/cassandra-3.11/docker-compose-dev-mode.yml Outdated Show resolved Hide resolved
@ivansenic
Copy link
Contributor

ivansenic commented Aug 30, 2022

Tried to answer to all the comments.. I'll do a final review on Thursday and we can hopefully merge then.

Since all the unit tests are green now, we should enable the int tests:

  1. Add required maven setup
    <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${surefire-plugin.version}</version>
    <executions>
    <execution>
    <goals>
    <goal>integration-test</goal>
    <goal>verify</goal>
    </goals>
    <configuration>
    <systemPropertyVariables>
    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
    <maven.home>${maven.home}</maven.home>
    <testing.containers.cassandra-image>${stargate.int-test.cassandra.image}:${stargate.int-test.cassandra.image-tag}</testing.containers.cassandra-image>
    <testing.containers.stargate-image>${stargate.int-test.coordinator.image}:${stargate.int-test.coordinator.image-tag}</testing.containers.stargate-image>
    <testing.containers.cluster-name>${stargate.int-test.cluster.name}</testing.containers.cluster-name>
    <testing.containers.cluster-version>${stargate.int-test.cluster.version}</testing.containers.cluster-version>
    <testing.containers.cluster-dse>${stargate.int-test.cluster.dse}</testing.containers.cluster-dse>
    </systemPropertyVariables>
    <includes>
    <include>**/*IntegrationTest.*</include>
    </includes>
    </configuration>
    </execution>
    </executions>
    </plugin>
  2. Enable project in CI:
    matrix:
    project: [ sgv2-docsapi ]
  3. Enable docker based test:
    - name: Integration Test
    env:
    CONTAINER_TEST: ${{ matrix.project == 'sgv2-docsapi' && 'true' || 'false' }}

@@ -10,6 +10,7 @@
<properties>
<quarkus.container-image.group>stargateio</quarkus.container-image.group>
<quarkus.container-image.name>graphqlapi</quarkus.container-image.name>
<quarkus.container-image.tag>v${project.version}</quarkus.container-image.tag>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our existing code prepends a "v" before the version, whereas Quarkus doesn't. I don't mind either way but if we drop it we'll have to adapt the coordinator and docker-compose scripts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add this to docs as well.. the release process correctly sets the tag with v, so this would be only for local builds and keeping that docker-compose stuff working

mem_limit: 2G
environment:
- STARGATE_BRIDGE_HOST=coordinator
- STARGATE_BRIDGE_PORT=8091
- STARGATE_GRAPHQL_PORT=9080
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We actually don't need to customize the port since the API is in its own container.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can still set the exposed port with -Dquarkus.http.port if needed..

@@ -75,11 +75,10 @@ services:
networks:
- stargate
ports:
- 9080:9080
- 8085:8080
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed the host port because I happen to have something already running on 9080 on my laptop.
Also it aligns better with what is used in the rest of the file.

Copy link
Contributor

@ivansenic ivansenic left a comment

Choose a reason for hiding this comment

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

Had one more look, I would say I have no more comments.. Open discussions should be resolved, tests should be green and we can merge this when @olim7t decides to do it.

Great work +1

Comment on lines 46 to 47
- STARGATE_BRIDGE_HOST=coordinator
- STARGATE_BRIDGE_PORT=8091
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can also just set QUARKUS_GRPC_CLIENTS_BRIDGE_HOST here and remove those env vars from docker compose completely..

@olim7t olim7t merged commit cd0467d into v2.0.0 Sep 2, 2022
@olim7t olim7t deleted the sgv2-graphqlapi-quarkus branch September 2, 2022 17:23
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.

4 participants