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

With MultiTenant deploy this.runScheduledRefresh(context, queryingOptions); context is null #1904

Closed
rongfengliang opened this issue Jan 27, 2021 · 5 comments · Fixed by #1921 or #1923 · May be fixed by jaanchristensen/cube.js#81, qsays/cube.js#188 or qsays/cube.js#190
Labels
docs Issues that require a documentation improvement enhancement New feature proposal

Comments

@rongfengliang
Copy link
Contributor

rongfengliang commented Jan 27, 2021

Describe the bug

contextappid: undefined
Refresh Scheduler Error: scheduler-40fb3cf1-c87a-424c-9b1e-5ffdd7182b0f 
{} 
TypeError: Cannot read property 'myappid' of undefined
    at CubejsServerCore.contextToAppId (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/cube.js:14:39)
    at CubejsServerCore.getCompilerApi (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/server-core/dist/src/core/server.js:293:28)
    at RefreshScheduler.runScheduledRefresh (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/server-core/dist/src/core/RefreshScheduler.js:82:49)
    at CubejsServerCore.runScheduledRefresh (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/server-core/dist/src/core/server.js:374:26)
    at /Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/server-core/dist/src/core/server.js:144:32
    at Array.map (<anonymous>)
    at CubejsServerCore.scheduledRefreshTimerInterval.shared_1.createCancelableInterval.interval (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/server-core/dist/src/core/server.js:139:44)
    at async Timeout._onTimeout (/Users/dalong/mylearning/cubejs-source/cubestorage-app/pre-age/node_modules/@cubejs-backend/shared/dist/src/promises.js:77:13)
contextappid: undefined

To Reproduce

run with express and config

   contextToAppId: ({ authInfo }) => {
        return `CUBEJS_APP_${authInfo.myappid}`
    },
    contextToOrchestratorId: ({ authInfo }) => {
        return `CUBEJS_APP_${authInfo.myappid}`
    },

Version:
[e.g. 0.25.30]

Additional context

maybe this cause

https://github.com/cube-js/cube.js/blob/master/packages/cubejs-server-core/src/core/server.ts#L228

cube.js config


change default:
scheduledRefreshContexts: async () => [null],
to (just do test for  RequestContext,maybe with externel restapi maybe better,or with some status for storage schedule context information)

scheduledRefreshContexts: async () => {
        return [{
            authInfo: {
                myappid: "demoappid",
                u: {
                    bucket: "demo"
                }
            }
        },
        {
            authInfo: {
                myappid: "demoappid2",
                u: {
                    bucket: "demo2"
                }
            }
        }]
}

@ovr
Copy link
Member

ovr commented Jan 27, 2021

I am not able to reproduce this issue on my local machine:

Config:

module.exports = {
  contextToAppId: (ctx) => {
    console.log('contextToAppId', ctx);
    return `CUBEJS_APP`
  },
  contextToOrchestratorId: (ctx) => {
    console.log('contextToOrchestratorId', ctx);
    return `CUBEJS_APP`
  },
  scheduledRefreshContexts: async () => {
    return [{
        authInfo: {
            myappid: "demoappid",
            u: {
                bucket: "demo"
            }
        }
    }]
  },
};

Result:

contextToAppId {
  requestId: 'scheduler-96e1cc18-68a1-40a0-9868-a81f60f4c8cd',
  authInfo: { myappid: 'demoappid', u: { bucket: 'demo' } }
}
contextToOrchestratorId {
  requestId: 'scheduler-96e1cc18-68a1-40a0-9868-a81f60f4c8cd',
  authInfo: { myappid: 'demoappid', u: { bucket: 'demo' } }
}

I have no ideas.

@rongfengliang
Copy link
Contributor Author

@ovr l mean without scheduledRefreshContexts config cube.js will throw exception . scheduledRefreshContexts must config when running with contextToAppId ?

@beefs
Copy link

beefs commented Jan 27, 2021

Run into the same issue when you use authInfo in preAggregationsSchema.

preAggregationsSchema: ({ authInfo }) => pa_${authInfo.aid},

And it will complain
TypeError: Cannot read property 'aid' of undefined
at CubejsServerCore.preAggregationsSchema

@ovr
Copy link
Member

ovr commented Jan 28, 2021

scheduledRefreshContexts must config when running with contextToAppId

Yes, because Cube.js is refreshing pre-aggregations/cache in the background, it's impossible to generate context(s) on the fly. You should declare scheduledRefreshContexts inside your configuration.

I will introduce a check to write an error message about it.

@rongfengliang
Copy link
Contributor Author

@ovr thanks, offical docs would description this for users who what use cube.js in multitenant environment

@hassankhan hassankhan added this to To Do in Roadmap 2021 Q1 via automation Jan 28, 2021
@hassankhan hassankhan added docs Issues that require a documentation improvement enhancement New feature proposal labels Jan 28, 2021
@hassankhan hassankhan moved this from To Do to Done in Roadmap 2021 Q1 Jan 28, 2021
@hassankhan hassankhan moved this from Done to To Do in Roadmap 2021 Q1 Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment