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

Exporting config w/ arrays in new platform plugin breaks #55576

Closed
jloleysens opened this issue Jan 22, 2020 · 3 comments · Fixed by #56105
Closed

Exporting config w/ arrays in new platform plugin breaks #55576

jloleysens opened this issue Jan 22, 2020 · 3 comments · Fixed by #56105
Assignees
Labels
blocker bug Fixes for quality problems that affect the customer experience Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@jloleysens
Copy link
Contributor

jloleysens commented Jan 22, 2020

Kibana version:

Master since at least 4ca2fbdb11

Describe the bug:

Given a config object like:

const configSchema = schema.object(
  {
    enabled: schema.boolean({ defaultValue: true }),
    proxyFilter: schema.arrayOf(schema.string(), { defaultValue: ['.*'] }),
    ssl: schema.object({ verify: schema.boolean({ defaultValue: false }) }, {}),

    // This does not actually work
    proxyConfig: schema.arrayOf(
      schema.object({
        match: schema.object({
          protocol: schema.string({ defaultValue: '*' }),
          host: schema.string({ defaultValue: '*' }),
          port: schema.string({ defaultValue: '*' }),
          path: schema.string({ defaultValue: '*' }),
        }),

        timeout: schema.number(),
        ssl: schema.object(
          {
            verify: schema.boolean(),
            ca: schema.arrayOf(schema.string()),
            cert: schema.string(),
            key: schema.string(),
          },
          { defaultValue: undefined }
        ),
      }),
      { defaultValue: [] }
    ),
  },
  { defaultValue: undefined }
)

Kibana fails to start when setting a proxyConfig like (2nd item not needed, just illustrating array) inside kibana.yml:

console.proxyConfig:
    - timeout: 20
      ssl:
        cert: ''
        ca:
          - bla
        verify: true
        key: ''
    - timeout: 20
      ssl:
        cert: ''
        ca:
          - bla
        verify: true
        key: ''

Error: Error: Unknown configuration key(s): "console.proxyConfig". Check for spelling errors and ensure that expected plugins are installed

Expected behavior:

Kibana should start as normal and provide config to the plugin. Validation of the object seems to be working.

Any additional context:

Looks like this is caused by this line:

const inputKeys = getFlattenedKeys(settings);

Returning a value like console.proxyConfig and then attempting to match against what it considers root paths like console.proxyConfig.0.timeout (the latter is not a subset of the former).

@jloleysens jloleysens added the bug Fixes for quality problems that affect the customer experience label Jan 22, 2020
@joshdover joshdover added Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Jan 27, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet
Copy link
Contributor

pgayvallet commented Jan 28, 2020

The way we flatten paths for the config's getUsedPaths considers arrays as objects, and therefor flatten the underneath keys.

function* flattenObjectKeys(
obj: { [key: string]: any },
path: string = ''
): IterableIterator<string> {
if (typeof obj !== 'object' || obj === null) {
yield path;
} else {
for (const [key, value] of Object.entries(obj)) {
const newPath = path !== '' ? `${path}.${key}` : key;
yield* flattenObjectKeys(value, newPath);
}
}
}

{a: [1, 2]} will flattenKey to ['a.0', 'a.1']

This is a difference with how the other parts of core (and legacy) was doing it, which preserves arrays at final values

/**
* Flattens a deeply nested object to a map of dot-separated
* paths pointing to all primitive values **and arrays**
* from `rootValue`.
*
* example:
* getFlattenedObject({ a: { b: 1, c: [2,3] } })
* // => { 'a.b': 1, 'a.c': [2,3] }
*
* @param {Object} rootValue
* @returns {Object}
*/
export function getFlattenedObject(rootValue: Record<string, any>) {

{a: [1, 2]} will flattenKey to ['a']

I think considering arrays as terminal values makes sense, and would fix this issue.

@restrry do you see any reason not to do this change?

@pgayvallet
Copy link
Contributor

Created #56105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker bug Fixes for quality problems that affect the customer experience Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants