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

Fleet: add support for subobjects: false #171826

Merged
merged 8 commits into from Dec 12, 2023
Merged

Conversation

zmoog
Copy link
Contributor

@zmoog zmoog commented Nov 23, 2023

Summary

Update the Fleet plugin to support the subobjects setting on the object type mapping.

This PR supports the subobjects setting on a per-field basis. We will add support for subobjects setting at the data stream level when Elasticsearch will automatically flatten the mappings in elastic/elasticsearch#99860.

The PR add deals with the following user cases found in the integration packages and add support for a few of them.

Case A

- name: a.labels
  type: object
  subobjects: false

The use case A is invalid on package-spec v3 and it's not supported.

Case B

- name: b.labels.*
  type: object
  object_type: keyword
  subobjects: false

that _generateMappings() should map to:

{
  dynamic_templates: [{
    "b.labels.*": {
      path_match: "b.labels.*",
      match_mapping_type: "string",
      mapping: {
        type: "keyword"
      }
    }
  }],
  properties: {
    b: {
      type: 'object',
      dynamic: true,
      properties: {
        labels: {
          dynamic: true,
          type: 'object',
          subobjects: false,
        }
      }
    },
  },
}

Case C

- name: prometheus.c.labels.*
  type: object
  subobjects: false

The use case C is considered invalid and it's not supported.

Case D

- name: d.labels
  type: object
  object_type: keyword
  subobjects: false

that _generateMappings() should map to:

{
  dynamic_templates: [{
    "d.labels": {
      path_match: "d.labels.*",
      match_mapping_type: "string",
      mapping: {
        type: "keyword"
      }
    }
  }],
  properties: {
    d: {
      type: 'object',
      dynamic: true,
      properties: {
        labels: {
          dynamic: true,
          type: 'object',
          subobjects: false,
        }
      }
    },
  },
}

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@zmoog zmoog self-assigned this Nov 23, 2023
@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@zmoog zmoog force-pushed the zmoog/subobjects-false branch 2 times, most recently from 78169c0 to 93a4249 Compare November 30, 2023 10:59
@zmoog zmoog changed the title Fleet: Add mapping for subobjects: false Fleet: add support for subobjects: false Nov 30, 2023
@zmoog zmoog marked this pull request as ready for review November 30, 2023 14:23
@zmoog zmoog requested a review from a team as a code owner November 30, 2023 14:23
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me. We should confirm first how this is going to be supported in package-spec, to know what cases should be supported.
Lets continue with elastic/package-spec#573 in parallel.

const objectFieldWithPropertyReversedLiteralYml = `
- name: a.labels
type: object
subobjects: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this mapping is not allowed in the package spec. It would not define a mapping for the sub fields of a.labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I agree.

I kept this case around if we found a compelling use case to resurrect it. There isn't one.

So, since it is not allowed in package-spec v3, I will drop this mapping from the PR.

const mappings = generateMappings(processedFields);
expect(mappings).toEqual(objectFieldWithPropertyReversedMapping);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test case where subobjects is used in an object without dynamic mappings? Something like this.

- name: a
  type: object
  subobjects: false
  fields:
    - name: b.c
      type: keyword
    - name: x.y
      type: keyword

For completeness, more than because I have some use case in mind 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

I added the test case in the template.test.ts file:

- name: a
  type: object
  subobjects: false
  fields:
    - name: b.c
      type: keyword
    - name: x.y
      type: keyword

And I am getting the following result:

{
  properties: {
    a: {
      type: 'object',
      subobjects: false,
    },
  },
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result is weird, but I think it's because to have fields, the type should be group, right?

I tried to add this to the good_v3 test package, and it complains about the type value:

type must be one of the following: "group", "nested"

Since the type is not group the content of fields is probably ignored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you are right, it should be type: group, not object, can you try to change it? Or well, maybe we don't need to support this use case, at least by now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looking to what we will likely do in the spec we don't need to support the case of the object with subfields.

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Nov 30, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@zmoog zmoog added the release_note:feature Makes this part of the condensed release notes label Dec 4, 2023
@zmoog
Copy link
Contributor Author

zmoog commented Dec 5, 2023

@jsoriano, do you think we're close to the finish line, or does this PR need more work? It would be great to have it in 8.12, if ready.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry it won't probably reach 8.12. Lets get this in and in the package spec so we can start testing with actual packages.

expect(mappings).toEqual(objectFieldWithPropertyReversedMapping);
});

it('tests processing object field with subobjects without dynamic mappings', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be probably removed as this won't be supported by the spec, as very well noticed in https://github.com/elastic/kibana/pull/171826/files#r1411644741

@zmoog
Copy link
Contributor Author

zmoog commented Dec 11, 2023

@elasticmachine merge upstream

1 similar comment
@zmoog
Copy link
Contributor Author

zmoog commented Dec 11, 2023

@elasticmachine merge upstream

zmoog and others added 8 commits December 11, 2023 18:13
Add support for the basic case:

    - name: b.labels.*
      type: object
      object_type: keyword
      subjects: false

that `_generateMappings()` should map to:

    {
        "properties": {
            "a": {
                "properties": {
                    "labels": {
                        "type": "object",
                        "subobjects": false
                    }
                }
            }
        }
    }
We consider case C invalid and we'll not support it.
Use case A is non allowed in package-spec v3.
We decided [^1] this is not a supported use case, dropping it.

[^1]: elastic#171826 (comment)
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @zmoog

@zmoog zmoog merged commit e6e10b5 into elastic:main Dec 12, 2023
45 checks passed
@zmoog zmoog deleted the zmoog/subobjects-false branch December 12, 2023 04:17
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:feature Makes this part of the condensed release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants