Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Setup the Autoconfiguration for Firestore Emulator #2244

Merged
merged 12 commits into from
Apr 21, 2020
Merged

Conversation

dzou
Copy link
Contributor

@dzou dzou commented Mar 9, 2020

Add support for using the Firestore emulator.

  • It is now enabled with spring.cloud.gcp.firestore.emulator.enabled=true and host port set via spring.cloud.gcp.firestore.host-port=xxxx.
  • In order to get it to work, we must disable stream tokens in the firestore template if the emulator is disabled; see notes below.

Fixes #1956.


Previous Notes:

If you try to run the reactive firestore sample with the emulator, you will get the error:

"Resuming streams is not supported, do not set stream ID."

The emulator will throw an error if you attempt to set stream/resume tokens in the request. However, our reactive Firestore Template uses this functionality and includes these tokens in the requests: see code

So resolving #1956 may not be possible in the end. Maybe this could benefit from a second set of eyes too.

@dzou dzou requested review from dmitry-s and meltsufin March 9, 2020 18:29
@dzou dzou added firestore Firestore Native mode support help wanted labels Mar 9, 2020
@dmitry-s
Copy link
Contributor

@dzou Can we disable setStreamToken if spring.cloud.gcp.firestore.emulator.enabled is set?

@dzou
Copy link
Contributor Author

dzou commented Mar 10, 2020

@dzou Can we disable setStreamToken if spring.cloud.gcp.firestore.emulator.enabled is set?

Ya I considered that, though I wasn't sure if it made sense to make the code accommodate the emulator since the emulator is test-only. What do you both think? @dmitry-s @meltsufin

@meltsufin
Copy link
Contributor

Let's wait for a response from the Firestore team.
b/151148092.

@dzou
Copy link
Contributor Author

dzou commented Apr 9, 2020

Will try following up again.

@codecov
Copy link

codecov bot commented Apr 15, 2020

Codecov Report

Merging #2244 into master will increase coverage by 0.25%.
The diff coverage is 89.36%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2244      +/-   ##
============================================
+ Coverage     73.54%   73.79%   +0.25%     
- Complexity     2078     2090      +12     
============================================
  Files           258      259       +1     
  Lines          7469     7510      +41     
  Branches        772      774       +2     
============================================
+ Hits           5493     5542      +49     
+ Misses         1620     1613       -7     
+ Partials        356      355       -1     
Flag Coverage Δ Complexity Δ
#integration ? ?
#unittests 73.79% <89.36%> (+0.25%) 2090.00 <10.00> (+12.00)
Impacted Files Coverage Δ Complexity Δ
...restore/GcpFirestoreEmulatorAutoConfiguration.java 84.84% <84.84%> (ø) 4.00 <4.00> (?)
...rk/cloud/gcp/data/firestore/FirestoreTemplate.java 76.25% <100.00%> (+9.08%) 49.00 <6.00> (+6.00)
...igure/firestore/GcpFirestoreAutoConfiguration.java 94.11% <0.00%> (+2.94%) 5.00% <0.00%> (+1.00%)
...utoconfigure/firestore/GcpFirestoreProperties.java 100.00% <0.00%> (+18.18%) 6.00% <0.00%> (+1.00%)

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 ac639ce...e0589fd. Read the comment docs.

Copy link
Contributor

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

@dzou I have left few messages :)

@dzou
Copy link
Contributor Author

dzou commented Apr 15, 2020

Thanks for the review @eddumelendez !

@meltsufin , @dmitry-s - I updated this PR so users should now be able to specify the host-port of a locally running emulator for firestore and it will work. The work to make this into a test resource can be deferred and grouped with the other work like with spanner emulator.

Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

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

A couple of technicality nits.

docs/src/main/asciidoc/firestore.adoc Show resolved Hide resolved
private static Credentials emulatorCredentials() {
final Map<String, List<String>> headerMap = new HashMap<>();
headerMap.put("Authorization", Collections.singletonList("Bearer owner"));
headerMap.put("google-cloud-resource-prefix", Collections.singletonList("projects/my-project/databases/(default)"));
Copy link
Contributor

Choose a reason for hiding this comment

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

"my-project" -- is it because it's a fake value that's unused? Can you leave a comment about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I just changed it to plug in the current project-id. I guess this is more technically correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe I should make this so the emulator config doesn't require a real project (and not inject a projectIdProvider into the configuration)... Maybe that would make more sense; what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just hardcode "unused" as project ID?

@dzou dzou requested review from meltsufin and elefeint April 17, 2020 22:24
elefeint
elefeint previously approved these changes Apr 20, 2020
Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

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

Looks good; I don't think the commit changing the project to current default came though, but then perhaps hardcoding a fake value is better anyway.

private static Credentials emulatorCredentials() {
final Map<String, List<String>> headerMap = new HashMap<>();
headerMap.put("Authorization", Collections.singletonList("Bearer owner"));
headerMap.put("google-cloud-resource-prefix", Collections.singletonList("projects/my-project/databases/(default)"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just hardcode "unused" as project ID?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

89.4% 89.4% Coverage
0.0% 0.0% Duplication

@dzou dzou requested a review from meltsufin April 20, 2020 20:58
Copy link
Contributor

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

LGTM

@elefeint
Copy link
Contributor

Can you update the PR description, since you've worked through all the problems by now? I use PR descriptions a lot when doing archaeological digs for why something is.

@dzou dzou changed the title [WIP] Setup the Autoconfiguration for Firestore Emulator Setup the Autoconfiguration for Firestore Emulator Apr 21, 2020
@dzou
Copy link
Contributor Author

dzou commented Apr 21, 2020

Can you update the PR description, since you've worked through all the problems by now? I use PR descriptions a lot when doing archaeological digs for why something is.

Will do!

@dzou dzou merged commit 85ff410 into master Apr 21, 2020
@dzou dzou deleted the firestore-emulator-wip branch April 21, 2020 13:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
firestore Firestore Native mode support help wanted
Development

Successfully merging this pull request may close these issues.

Firestore implement/document emulator support
5 participants