cube icon indicating copy to clipboard operation
cube copied to clipboard

cubejs/cube:v0.35.11 results in Model files not found errors

Open alyssakelley opened this issue 1 year ago • 1 comments

Describe the bug When we use any version of cubejs/cube past v0.35.10, our cube deployment results in the following errors:

"error": "Error: Model files not found. Please make sure the "model" directory exists and contains model files.", "stack": "Error: Model files not found. Please make sure the "model" directory exists and contains model files.\n at FileRepository.getFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:31:13)\n at FileRepository.dataSchemaFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:46:19)\n at DataSchemaCompiler.doCompile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:81:19)\n at CompilerApi.getCompilers (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:67:26)\n at CompilerApi.metaConfig (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:221:23)\n at ApiGateway.load (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:1597:30)\n at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:257:7"

We are deploying cube to aks following a similar chart structure as what is documented here: https://github.com/cube-js/cube/tree/master/examples/kubernetes/cluster

To Reproduce Steps to reproduce the behavior:

  1. Use cubejs/cube:v0.35.11 or greater
  2. Have cube image deployed with cube.js file in root
  3. Port forward cube-api service: kubectl port-forward -n cube svc/cube-api 4000
  4. Make a test api call to http://localhost:4000/cubejs-api/v1/load with a valid query parameter included
  5. See the error in api output and cube-api pod logs

Expected behavior Expect the api results to come back with valid data from our ConfigMap that was specified in the query parameter of the call.

Screenshots If applicable, add screenshots to help explain your problem. api_error

Version: v0.35.11 through latest does not work

Example cube.js file in root

module.exports = {
    checkAuth: ({ securityContext }, token) => {
      if (token !== null) {
        return;
      }
      
      throw new Error(`Access denied - securityContext: ${securityContext} - token: ${token}`);
    },
    orchestratorOptions: {
      continueWaitTimeout: 15  
    }
  };

alyssakelley avatar Apr 30 '24 22:04 alyssakelley

@alyssakelley schema path should be updated to be model indeed.

paveltiunov avatar May 01 '24 03:05 paveltiunov

The solution is updating cube.js in the root of the image to be something similar to:


const path = require("path");
const fs = require("fs");

module.exports = {
  checkAuth: ({ securityContext }, token) => {
    if (token !== null) {
      return;
    }
    throw new Error(`Access denied - securityContext: ${securityContext} - token: ${token}`);
  },
  orchestratorOptions: {
    continueWaitTimeout: 15
  },
  repositoryFactory: () => ({
    dataSchemaFiles: async () => {
      const files = await fs.promises.readdir(
        path.join(process.cwd(), "model")
      );
      return await Promise.all(
        files
          .filter((file) => file.endsWith(".js") || file.endsWith(".yaml"))
          .map(async (file) => ({
            fileName: file,
            content: await fs.promises.readFile(
              path.join(process.cwd(), "model", file),
              "utf-8"
            ),
          }))
      );
    },
  })
};

and then making sure the volume mount is updated in the cube-api deployment

alyssakelley avatar May 23 '24 19:05 alyssakelley

The problem still remains, providing a workaround is appreciated but is not a solution. I believe this ticket should be re-opened.

rcarcasses avatar Jul 22 '24 14:07 rcarcasses

It happens to me as well when upgreading cube from 34 to 35 (latest one). All my existing queries failed with:

"error": "Error: Model files not found. Please make sure the \"model\" directory exists and contains model files.",
    "stack": "Error: Model files not found. Please make sure the \"model\" directory exists and contains model files.\n    at FileRepository.getFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:31:13)\n    at FileRepository.dataSchemaFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:46:19)\n    at CompilerApi.getCompilers (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:55:21)\n    at CompilerApi.metaConfig (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:231:23)\n    at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:273:28",
    "requestId": "cc639dca-c76e-4135-8ce4-c9d522fde3ff-span-1"

kevinleeTCA avatar Jul 31 '24 03:07 kevinleeTCA

Hi @paveltiunov , do we have any guideline doc on upgrading cube from 34 to 35, as we encounter this issue

"error": "Error: Model files not found. Please make sure the \"model\" directory exists and contains model files.",
    "stack": "Error: Model files not found. Please make sure the \"model\" directory exists and contains model files.\n    at FileRepository.getFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:31:13)\n    at FileRepository.dataSchemaFiles (/cube/node_modules/@cubejs-backend/shared/src/FileRepository.ts:46:19)\n    at CompilerApi.getCompilers (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:55:21)\n    at CompilerApi.metaConfig (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:231:23)\n    at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:273:28",
    "requestId": "cc639dca-c76e-4135-8ce4-c9d522fde3ff-span-1"

when we did the upgrade, this is one of the breaking change mentioned here, however, it has no guideline on how to resolve these breaking changes. Any helpful doc or hints would be much appreciated.

kevinleeTCA avatar Aug 02 '24 04:08 kevinleeTCA

I resolved by explicitly adding the path in the config (following the doc here):

module.exports = {
  schemaPath: 'my-data-model'
};

kevinleeTCA avatar Aug 06 '24 06:08 kevinleeTCA