Skip to content

metricbeat: add integration TestIndexTotalFieldsLimitNotReached #41698

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

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

AndersonQ
Copy link
Member

@AndersonQ AndersonQ commented Nov 20, 2024

Proposed commit message

metricbeat: add integration TestIndexTotalFieldsLimitNotReached

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

This new test will start failing when the metricbeat mapping has increased to the point it isn't possible to add a new event with 500 dynamically mapped fields. It should act as a safe guard to prevent us from releasing a version where the static mapping is too close to the total fields limit.

Checklist

  • My code follows the style guidelines of this project
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

  • N/A

How to test this PR locally

  • build x-pack/metricbeat
    • cd x-pack/metricbeat
    • go build .
  • adjust metricbeat.yml to point to your stack and make sure to include setup.kibana.host
  • run ./metricbeat setup
  • generate an event with 500 dynamic fields. Just use the same for loop the test uses
  • ingest the event:
POST metricbeat-9.0.0/_doc
{ 
   ...
}
  • it should succeed
  • change the index.mapping.total_fields.limit for the metricbeat index template:
    • go to your-kibna/app/management/data/index_management/templates/metricbeat-9.0.0
    • metricbeat-9.0.0 > Manage > Edit > 3 Index settings
    • change index.mapping.total_fields.limit to 10000:
"mapping": {
      "total_fields": {
        "limit": "10000"
      }
  • rollover the index
POST metricbeat-9.0.0/_rollover
  • try to ingest the same event again, you should get an error like:
{
  "error": {
    "root_cause": [
      {
        "type": "document_parsing_exception",
        "reason": "[1:378] failed to parse: Limit of total fields [10000] has been exceeded while adding new fields [11]"
      }
    ],
    "type": "document_parsing_exception",
    "reason": "[1:378] failed to parse: Limit of total fields [10000] has been exceeded while adding new fields [11]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Limit of total fields [10000] has been exceeded while adding new fields [11]"
    },
    "failure_store": "not_enabled"
  },
  "status": 400
}

Related issues

@AndersonQ AndersonQ self-assigned this Nov 20, 2024
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 20, 2024
@AndersonQ AndersonQ force-pushed the 3786-test-for-field-limit-exceed branch from 779abce to b9722e4 Compare November 20, 2024 08:32
Copy link
Contributor

mergify bot commented Nov 20, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @AndersonQ? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Nov 20, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Nov 20, 2024
@AndersonQ AndersonQ added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Nov 20, 2024
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 20, 2024
@AndersonQ AndersonQ added backport-8.15 Automated backport to the 8.15 branch with mergify backport-8.16 Automated backport with mergify labels Nov 20, 2024
@AndersonQ AndersonQ force-pushed the 3786-test-for-field-limit-exceed branch from b9722e4 to 5fa28a7 Compare November 20, 2024 10:06
@AndersonQ AndersonQ changed the title wip: TestIndexTotalFieldsLimit metricbeat: add integration TestIndexTotalFieldsLimitNotReached Nov 20, 2024
The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.
@AndersonQ AndersonQ marked this pull request as ready for review November 20, 2024 10:42
@AndersonQ AndersonQ requested a review from a team as a code owner November 20, 2024 10:42
@AndersonQ AndersonQ requested review from rdner and mauri870 November 20, 2024 10:43
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@AndersonQ AndersonQ force-pushed the 3786-test-for-field-limit-exceed branch from 5fa28a7 to df48d3b Compare November 20, 2024 13:12
@AndersonQ AndersonQ marked this pull request as draft November 20, 2024 14:13
@AndersonQ AndersonQ changed the title metricbeat: add integration TestIndexTotalFieldsLimitNotReached WIP: metricbeat: add integration TestIndexTotalFieldsLimitNotReached Nov 20, 2024
@AndersonQ AndersonQ changed the title WIP: metricbeat: add integration TestIndexTotalFieldsLimitNotReached metricbeat: add integration TestIndexTotalFieldsLimitNotReached Nov 20, 2024
@AndersonQ AndersonQ marked this pull request as ready for review November 20, 2024 15:53
"-E", "output.file.enabled=false")
procState, err := metricbeat.Process.Wait()
require.NoError(t, err, "metricbeat setup failed")
require.Equal(t, 0, procState.ExitCode(), "metircbeat setup failed: incorrect exit code")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
require.Equal(t, 0, procState.ExitCode(), "metircbeat setup failed: incorrect exit code")
require.Equal(t, 0, procState.ExitCode(), "metricbeat setup failed: incorrect exit code")

require.NoError(t, err, "could not send request to send event to ES")
defer resp.Body.Close()

failuremsg := fmt.Sprintf("filed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the envent was not ingested", totalFields, index)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
failuremsg := fmt.Sprintf("filed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the envent was not ingested", totalFields, index)
failuremsg := fmt.Sprintf("failed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the event was not ingested", totalFields, index)

defer resp.Body.Close()

failuremsg := fmt.Sprintf("filed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the envent was not ingested", totalFields, index)
if !assert.Equal(t, http.StatusCreated, resp.StatusCode, failuremsg) {
Copy link
Member

Choose a reason for hiding this comment

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

Could use assert.NotEqual here

Copy link
Member Author

Choose a reason for hiding this comment

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

not really. I want to assert it's equal, if the assertion fails, then the extra code runs to help to explain what went wrong

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

r, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewBuffer(event))
Copy link
Member

Choose a reason for hiding this comment

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

I recall seeing tests that need to interact with Elasticsearch that use the libbeat es client. I think this is preferable to avoid code duplication.

Copy link
Member

@mauri870 mauri870 left a comment

Choose a reason for hiding this comment

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

LGTM Left some comments, but overall the test seems correct to me.

The linter error seems to be the same one that Lee faced this week, caused by an old version of golangci-lint.

@belimawr belimawr self-requested a review November 22, 2024 15:06
_, _, err = integration.HttpDo(t, http.MethodDelete, templateURL)
require.NoErrorf(t, err, "cleanup failed: could not remove index template %s", index)
_, _, err = integration.HttpDo(t, http.MethodDelete, policyURL)
require.NoErrorf(t, err, "cleanup failed: could not ilm policy %s", index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo:

Suggested change
require.NoErrorf(t, err, "cleanup failed: could not ilm policy %s", index)
require.NoErrorf(t, err, "cleanup failed: could not remove ilm policy %s", index)

Comment on lines 57 to 58
// ensure datastream/index template/ ilm policy is set before running the test
cleanUpES()
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean?

You're removing them all, however you wrote about ensuring they're set... I'm confused on what you're trying to accomplish here.

"-E", "setup.kibana.port="+kURL.Port(),
"-E", "output.elasticsearch.protocol=http",
"-E", "output.elasticsearch.hosts=['"+esURL.String()+"']",
"-E", "output.file.enabled=false")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to set the file output to false?

Suggested change
"-E", "output.file.enabled=false")

"-E", "output.file.enabled=false")
procState, err := metricbeat.Process.Wait()
require.NoError(t, err, "metricbeat setup failed")
require.Equal(t, 0, procState.ExitCode(), "metricbeat setup failed: incorrect exit code")
Copy link
Contributor

Choose a reason for hiding this comment

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

[Suggestion]
Add the exit code to the error message.

Suggested change
require.Equal(t, 0, procState.ExitCode(), "metricbeat setup failed: incorrect exit code")
require.Equalf(t, 0, procState.ExitCode(), "metricbeat setup failed: incorrect exit code: %d", procState.ExitCode())

@cmacknz
Copy link
Member

cmacknz commented Nov 22, 2024

Just to confirm, if you revert #41640 this test fails immediately?

@AndersonQ AndersonQ merged commit 8a2724a into elastic:main Nov 22, 2024
18 of 21 checks passed
require.NoError(t, err, "could not send request to send event to ES")
defer resp.Body.Close()

failuremsg := fmt.Sprintf("failed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the event was not ingested", totalFields, index)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
failuremsg := fmt.Sprintf("failed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to be reached. Check the logs to see why the event was not ingested", totalFields, index)
failuremsg := fmt.Sprintf("failed to ingest events with %d new fields. If this test fails it likely means the current `index.mapping.total_fields.limit` for metricbeat index (%s) is close to being reached. Check the logs to see why the event was not ingested", totalFields, index)

mergify bot pushed a commit that referenced this pull request Nov 22, 2024
The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)
mergify bot pushed a commit that referenced this pull request Nov 22, 2024
The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)
mergify bot pushed a commit that referenced this pull request Nov 22, 2024
The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)
"github.com/elastic/beats/v7/libbeat/version"
)

func TestIndexTotalFieldsLimitNotReached(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I would add some explicit documentation for why this test exists and that it is a regression test for #41614 specifically.

This test is likely to fail for seemingly unrelated changes so let's go overboard with documenting the problem it is detecting.

@cmacknz
Copy link
Member

cmacknz commented Nov 22, 2024

Just to confirm, if you revert #41640 this test fails immediately?

I see this was answered in the description reading it again 👍

@pierrehilbert pierrehilbert added the backport-8.17 Automated backport with mergify label Nov 25, 2024
mergify bot pushed a commit that referenced this pull request Nov 25, 2024
The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)
Kavindu-Dodan pushed a commit to Kavindu-Dodan/beats that referenced this pull request Nov 27, 2024
…tic#41698)

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.
AndersonQ added a commit that referenced this pull request Dec 2, 2024
…) (#41757)

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)

Co-authored-by: Anderson Queiroz <[email protected]>
AndersonQ added a commit that referenced this pull request Dec 2, 2024
…) (#41758)

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)

Co-authored-by: Anderson Queiroz <[email protected]>
AndersonQ added a commit that referenced this pull request Dec 2, 2024
…) (#41759)

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)

Co-authored-by: Anderson Queiroz <[email protected]>
AndersonQ added a commit that referenced this pull request Dec 2, 2024
…) (#41768)

The new integration test TestIndexTotalFieldsLimitNotReached ensures events with at least 500 new dynamically mapped fields can be ingested.

(cherry picked from commit 8a2724a)

Co-authored-by: Anderson Queiroz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.15 Automated backport to the 8.15 branch with mergify backport-8.16 Automated backport with mergify backport-8.17 Automated backport with mergify Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants