I've implemented real time remote config updates via the documentation here.
In general, it works as expected, except when it comes to experiments via A/B Testing. Changes to A/B Testing that affect remote config do not fire the update cloud function hook.
Does anyone know if its possible to have the functions.remoteConfig.onUpdate cloud function hook trigger when a change to remote config is made via an A/B Testing experiment change?
The only workaround I can think of is to have a dummy value in remote config itself that I change whenever an experiment is created/updated.
firebaser here
There is nothing built into Remote Config for that at the moment. But thanks to the integration between Cloud Functions and Remote Config, you can build it yourself.
One of our engineers actually just gave a demo for this last week. I recommend you check it out here: https://youtu.be/lIzQJC21uus?t=3351.
In this demo, there are a few steps:
You publish a change from the Remote Config console.
This change triggers Cloud Functions through a functions.remoteConfig.onUpdate event.
The Cloud Function sends an FCM message to all apps through a topic.
When an app receives this message, it shows a prompt that the configuration is out of date.
When the user clicks the "fetch" button, the app fetches the new configuration data from Remote Config.
Related
So I am switching from cloud functions to Cloud Run and I am trying to figure out how to run Event Arc locally. I know you can set up an emulator for Eventarc using Firebase Emulator but Im not sure to have it trigger one of my Cloud Run functions when I write to my local Firestore db. Can someone please let me know how this can be done?
I did see one vague answer here:
Emulation of event-driven design in Cloud Run while developing locally?
But to me this doesn't make sense given that if Im using the local DB and local functions how would a remote instance work with my local dev environment. If this is possible please let me know and how I can accomplish this. Thanks.
It's not an easy task and the team is working to make the local tests easier. For now, I can share my hack.
First of all, you have to know that eventarc is roughtly a wrapper that create several resources behind the scene, especially a PubSub topic and Push subscription to your Cloud Run service. Because of that, an eventarc event is no more than a POST request with the event content as body.
For my hack, I have a Cloud Run service, on GCP, that log the headers and body of any incoming requests. I set up an eventarc with that service as target, and I trigger an event.
I go to the logs, copy the headers and the body of the received event, and I create a curl POST request with that.
Then, when I want to test my local service, I reuse my curl POST request, and submit it to my localhost server.
I am using Cypress for end-to-end testing an application, together with the cypress-firebase package. I followed the official setup instructions (using TypeScript, and the Firebase Web SDK version 9 with the compat mode).
In my tests, calling cy.login() seems to work as expected in that Cypress logs that the createCustomToken task successfully performs two HTTP POSTs with status code 200 each.
However, when visiting a page of the application afterwards, no user is logged in. In the application, the login status is supposed to be detected using Firebase's onAuthStateChanged function. It seems that cy.login() never triggers onAuthStateChanged, though.
My best guess is that maybe the auth instances used by cypress-firebase and the application code are not the same?! Is there a way to confirm this, or could there be another reason?
Happy to provide further information if it may help.
The issue was indeed related to auth instances not matching: The application was using a named instance, whereas the initializeApp code in Cypress was not naming the app (and thus relying in an app instance named [DEFAULT]).
Fortunately, cypress-firebase has support for named apps:
const namedApp = firebase.initializeApp(fbConfig, "app_name");
attachCustomCommands({ Cypress, cy, firebase, app: namedApp });
There is a service that is publishing messages to my Pub/Sub. Via CLI, I know it is receiving properly the messages.
I want to react correspondingly to those messages. However, I want to develop my subscription, via Cloud Functions, in development environment (firebase emulator), so I won't have to wait 5min between each deploy. But, when using functions.pubsub.topic('topicName').onPublish(...), it won't subscribe to the real prod messages, looks like it will only subscribe to the dev env ones.
I want to, in my firebase emulated Sub/Pub, subscribe to prod messages. Is it possible to do it? How?
Still haven't found an "official" way.
What I am doing for now is use ngrok, get the local function url and then enter it in Pub/Sub Subscription in Push mode. It's a longer way and will require updating the ngrok url for each session (as its url changes in free tier), and also to get the data, JSON.parse(Buffer.from(req.body.message.data, 'base64').toString('utf-8')) and still haven't found a way to auth the JWT auth from request.
But, I can now get the Prod messages from my Firebase Emulator, as I want. You may comment here to ask for further infos about that workaround of mine.
I'm currently running an A/B test on a remote config value in Firebase. The target of the test is for users with a user property X that is contained in a regex.
My problem is that I fetch the remote configs for the user BEFORE setting the user property, so I need to update the remote config when the user property is set. So basically, a force update of a remote config (that is updated because the user is now part of the AB test).
Any ideas?
This article will help you.
Force your users to update your app with using firebase
This code will set app to fetch every minutes.
firebaseRemoteConfig.fetch(60)
But this method does not force update app.
So, I suggest you to all server APIs implement the functionality to do version checking. For example, if your app version was updated, all of APIs will return "You need to update your app" error.
Be careful with Firebase updates on both: iOS and Android. You can read more about it here: https://medium.com/#elye.project/be-careful-when-using-firebase-remote-config-control-for-pre-announced-feature-52f6dd4ecc18
On iOS config can be force updated with following code:
config.fetch(withExpirationDuration: 0, completionHandler: fetchCompletion)
I am new to Firebase, I setup a project and using nodejs + nestjs
I have a https trigger function that adds record to Firestore
I have a Firestore document onCreate trigger, to duplicate data to another collection
Then I try to run Firebase locally by running npm run serve which is calling firebase serve --only functions
Then I can access the https function via postman app.
First problem is Firestore onCreate trigger is not fired locally when I call my local https function.
Second problem is Firestore onCreate trigger is run on server and I can see running logs, which means in development time, some buggy bad code could be running on server and that code might corrupt data (while the good code is under development and bugs are fixing on my local)
So my question is, how usually people do development on their local and testing?
firebase serve --only functions only emulates HTTPS functions.
firebase experimental:functions:shell works with everything else, but you have to construct stub data to send to it.
See the documentation for more information:
Run Functions Locally
Unit testing functions