mongodb-js / charts-embed-sdk

The easiest way to embed MongoDB Charts visualisations into your web app
https://docs.mongodb.com/charts/master/embedding-charts-sdk/
Apache License 2.0
43 stars 31 forks source link

Dashboard sometimes failing to fetch #83

Closed lukeobvio closed 3 months ago

lukeobvio commented 1 year ago

Getting error "Failed to fetch" when rendering a dashboard (created with the createDashboard method from the ChartsEmbedSDK). This only happens sometimes, usually the first time dashboard.render() is invoke. We were able to get around this by trying a second time.

Steps to reproduce the behavior:

  1. Create a dashboard using the ChartsEmbedSDK
  2. Attempt to render
  3. Sometimes it will fail with error "Failed to fetch"

Desktop Info:

kristinamongo commented 1 year ago

Hi @lukeobvio, sorry to hear about this.

I couldn't repro the behaviour you described. Could you give us the snippet of code you use for rendering the dashboard? That might help us investigate what is happening.

Also, is there any console error with more details, or any more info in the the network request response? Is it "failed to fetch" all charts in the dashboard? A screenshot will be great 🙏

lukeobvio commented 1 year ago

Hi @kristinamongo, thank you for your quick response!

Yes, I get the "Failed to Fetch" error when the entire dashboard screen is loading - once the individual dashboards show up as "loading", it goes on to succeed. Here's the code snippet that is rendering the dashboard:

            const sdk = new ChartsEmbedSDK({
                baseUrl,
            });
            const dashboard = sdk.createDashboard({
                dashboardId,
                getUserToken: idToken,
            });
            const element = document.getElementById('mongo');
            const mongo = element as HTMLElement;
            dashboard.render(mongo).catch((e) => {
                console.log(Mongo Error);
                console.log(e);
                if (retryMongo) {
                    setRenderError(true);
                    setRetryMongoRender(false);
                } else {
                    setRetryMongoRender(true);
                    getMongoDashboard();
            }

I'm also attaching a screenshot as requested, although it does not contain a lot of information. The second line in the console output shows the error that I'm getting back from Mongo: "Failed to fetch". (After encountering this issue, I've implemented retrying logic. In the screenshot below, the chart has successfully rendered in the 2nd attempt)

Screenshot 2023-06-28 at 3 54 05 PM
kristinamongo commented 1 year ago

Thank you @lukeobvio, the snippet looks correct. Could you just make sure that the token is available when the first render call is made (the failing call)? Also, would it be ok if you share the dashboardId for investigation purposes? A security note here that even with the dashboardId we can't access your dashboard. I'm asking as it would help to do a deeper search in the logs.

lukeobvio commented 1 year ago

Hi @kristinamongo, the dashboardId used in the screenshot above is: 648894ca-8f6c-43b4-854a-61b48d5527a6. But we experienced this with multiple different dashboards. Regarding the token: our code loads the token upfront, when loading the page. So I could understand the token being the issue if loading the dashboard failed when first loading the page, but we've mainly seen this issue when first attempting to load a dashboard after the page has already loaded. Once the new information is put in, we actually see the mongo "small graph" loading icon on the screen for a couple of seconds before it errors with "failed to fetch"

kristinamongo commented 1 year ago

Hi @lukeobvio, apologies for the delay of this response, however I have not been able to find the cause of the issue you are experiencing. :(

There is a slight chance it could have been fixed by a patch we released yesterday. Do you mind checking with version 3.2.1?

If it still fails to fetch, I would need a bit more help from your side to investigate this. If you could repro the issue with an unauthenticated dashboard that I can use for debugging and investigation, that would help a lot.

kristinamongo commented 3 months ago

Closing this due to inactivity. Feel free to open a new issue if you can repro with an unauthenticated dashboard so we can investigate further.