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

Asset loading test runner #168

Merged
merged 34 commits into from
Jan 18, 2021
Merged

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Nov 10, 2020

This PR implements a new type of test runner: asset. This test runner tests whether a package's assets (ES index templates, Kibana dashboards, etc.) are loaded up as expected.

Sample usage

$ elastic-package test asset
Run asset tests for the package
--- Test results for package: apache - START ---
╭─────────┬─────────────┬───────────┬────────────────────────────────────────────────────────────────┬────────┬──────────────╮
│ PACKAGE │ DATA STREAM │ TEST TYPE │ TEST NAME                                                      │ RESULT │ TIME ELAPSED │
├─────────┼─────────────┼───────────┼────────────────────────────────────────────────────────────────┼────────┼──────────────┤
│ apache  │             │ asset     │ dashboard apache-Logs-Apache-Dashboard is loaded               │ PASS   │ 6.101128287s │
│ apache  │             │ asset     │ dashboard apache-Metrics-Apache-HTTPD-server-status is loaded  │ PASS   │        927ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-CPU is loaded                       │ PASS   │        620ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Hostname-list is loaded             │ PASS   │        512ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Load1-slash-5-slash-15 is loaded    │ PASS   │        526ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Scoreboard is loaded                │ PASS   │        430ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Total-accesses-and-kbytes is loaded │ PASS   │        424ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Uptime is loaded                    │ PASS   │        416ns │
│ apache  │             │ asset     │ visualization apache-HTTPD-Workers is loaded                   │ PASS   │        403ns │
│ apache  │             │ asset     │ visualization apache-access-unique-IPs-map is loaded           │ PASS   │        404ns │
│ apache  │             │ asset     │ visualization apache-browsers is loaded                        │ PASS   │        413ns │
│ apache  │             │ asset     │ visualization apache-error-logs-over-time is loaded            │ PASS   │        410ns │
│ apache  │             │ asset     │ visualization apache-operating-systems is loaded               │ PASS   │        407ns │
│ apache  │             │ asset     │ visualization apache-response-codes-of-top-URLs is loaded      │ PASS   │        439ns │
│ apache  │             │ asset     │ visualization apache-response-codes-over-time is loaded        │ PASS   │        453ns │
│ apache  │             │ asset     │ search apache-HTTPD is loaded                                  │ PASS   │        598ns │
│ apache  │             │ asset     │ search apache-access-logs is loaded                            │ PASS   │        420ns │
│ apache  │             │ asset     │ search apache-errors-log is loaded                             │ PASS   │        514ns │
│ apache  │ access      │ asset     │ index_template logs-apache.access is loaded                    │ PASS   │        490ns │
│ apache  │ access      │ asset     │ ingest_pipeline logs-apache.access-0.2.7 is loaded             │ PASS   │        462ns │
│ apache  │ error       │ asset     │ index_template logs-apache.error is loaded                     │ PASS   │        405ns │
│ apache  │ error       │ asset     │ ingest_pipeline logs-apache.error-0.2.7 is loaded              │ PASS   │        434ns │
│ apache  │ status      │ asset     │ index_template metrics-apache.status is loaded                 │ PASS   │        440ns │
╰─────────┴─────────────┴───────────┴────────────────────────────────────────────────────────────────┴────────┴──────────────╯
--- Test results for package: apache - END   ---
Done

TODO

  • Install package
  • Remove package
  • Add assertions on asset existence
  • Move --data-stream global test flag to pipeline and system tests
  • Add HOWTO doc
  • Add to README doc
  • Update CI configuration

Resolves #115.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Nov 10, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #168 updated

    • Start Time: 2021-01-15T19:34:03.452+0000
  • Duration: 11 min 19 sec

  • Commit: 133e50e

Test stats 🧪

Test Results
Failed 0
Passed 67
Skipped 0
Total 67

@ycombinator
Copy link
Contributor Author

@mtojek This PR is ready for review, when you get a chance.

Before this PR we had 2 test runners, both of which operated at the data stream level and needed test configuration. This PR introduces a test runner that operates at the package level and also doesn't need test configuration. As a result, the code for the test runner framework is now a bit of a mess IMO. I would like to clean this up but in a follow up PR. WDYT?

@ycombinator ycombinator changed the title [WIP] Asset loading test runner Asset loading test runner Nov 17, 2020
internal/packages/assets.go Outdated Show resolved Hide resolved
internal/kibana/ingestmanager/client_packages.go Outdated Show resolved Hide resolved

// RemovePackage removes the given package from Fleet.
func (c *Client) RemovePackage(pkg packages.PackageManifest) ([]packages.Asset, error) {
return managePackage(pkg, "remove", c.delete)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a gut feeling that clients in ingestmanager are too much complex. Not sure if we need as many layers to process a single request. Maybe not depending on common abstraction would be simpler?

Please take a look at https://github.com/elastic/elastic-package/blob/master/internal/kibana/saved_objects.go . In this case I need to implement paging and the exact code responsible for calls to Kibana is wrapped up in ca. 20 LOCs: https://github.com/elastic/elastic-package/blob/master/internal/kibana/saved_objects.go#L95-L118

I'm happy to discuss it!

}
assets = append(assets, a...)

a, err = loadFileBasedAssets(kibanaAssetsFolderPath, AssetTypeKibanaMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking loud: shouldn't elastic-package discover available types from the package directory? In case we add a new type the command will still operate (open-closed principle).

internal/packages/assets.go Outdated Show resolved Hide resolved
internal/testrunner/runners/asset/runner.go Show resolved Hide resolved
internal/testrunner/runners/asset/runner.go Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
format_version: 1.0.0
name: apache
title: Apache
version: 0.1.4
version: 0.2.7
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I had to make it because the package registry image loaded up by the tests installs Apache version 0.2.6. So, in order for the asset test runner to be able to install the local apache package (i.e. the one being tested), I had to ensure that the local apache package's version was greater than the one in the registry. Otherwise the Install Package API would not allow the local package to be loaded up.

I admit that this is not a very maintainable change. Every time the package registry image is refreshed with a newer version of apache, we will need to bump up the version here as well. Maybe we should just set it here to something like 999.999.999?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see :) In this case you can set it to sth weird like 999. (at least the major). Nice catch!

for d in test/packages/*/; do
(
cd $d
elastic-package build -v
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please double-check if the check command doesn't include build step?

internal/testrunner/testrunner.go Outdated Show resolved Hide resolved
@mtojek mtojek mentioned this pull request Nov 19, 2020
@ycombinator
Copy link
Contributor Author

TODO: consider implementing #175 (comment) as part of this PR.

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

@ycombinator please let me know whether I can take another look at this PR.

@ycombinator
Copy link
Contributor Author

please let me know whether I can take another look at this PR.

Yeah, I'm still iterating on it. I'll re-request your review when it's ready for you to take a look. Thanks!

@ycombinator
Copy link
Contributor Author

I see that CI is failing. I will look into this tomorrow.

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

The implementation looks good to me.

Let's move forward with this PR. Did you take a chance to run it against real integrations?

nit: just rebase the PR against master branch

@ycombinator
Copy link
Contributor Author

Seeing this error now:

$ elastic-package test -v --report-format xUnit --report-output file --defer-cleanup 1s
elastic-package has been installed.
2021/01/14 15:49:34 DEBUG Enable verbose logging
Run test suite for the package
Run asset tests for the package
2021/01/14 15:49:34 DEBUG installing package...
2021/01/14 15:49:34 DEBUG POST http://127.0.0.1:5601/api/fleet/epm/packages/apache-999.999.999
2021/01/14 15:49:34 DEBUG
2021/01/14 15:49:43 DEBUG waiting for 1s before tearing down...
Run pipeline tests for the package
Error: error parsing --data-streams flag: flag accessed but not defined: data-streams

Will look into it tomorrow.

@ycombinator
Copy link
Contributor Author

Hi @mtojek, I made a few small changes since your last review to make CI pass. Could you please take another look when you get a chance? Thanks!

@ycombinator ycombinator mentioned this pull request Jan 15, 2021
3 tasks
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Thank you for the heads up! I left some minor comments, but wouldn't like to block your PR from merging. These ones can be addressed in follow up PRs (up to you).

I'm thrilled to see this running in the Integrations. Nice job!

AssetTypeKibanaSavedSearch AssetType = "search"
AssetTypeKibanaVisualization AssetType = "visualization"
AssetTypeKibanaDashboard AssetType = "dashboard"
AssetTypeKibanaMap AssetType = "map"
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Lens

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 133e50e.

@@ -51,17 +51,6 @@ type runner struct {
wipeDataStreamHandler func() error
}

type stackSettings struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the stackSettings (old and new) structure used anywhere? It looks like a leftover after refactoring. All stack settings like host, login, password don't need to be exposed beyond ES/Kibana clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I've removed all stack settings code in cef5f22. So now the ES/Kibana clients directly call os.Getenv in their constructors to get the stack settings.

internal/packages/packages.go Show resolved Hide resolved
@@ -223,5 +237,5 @@ func isDataStreamManifest(path string) (bool, error) {
if err != nil {
return false, errors.Wrapf(err, "reading package manifest failed (path: %s)", path)
}
return m.Title != "" && (m.Type == "logs" || m.Type == "metrics"), nil
return m.Title != "" && (m.Type == dataStreamTypeLogs || m.Type == dataStreamTypeMetrics), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Actually this function isn't perfect. If there is another dataset type, it will simply fail (OCP broken). I wonder if there is a different way to recognize the DataStream. If you find any, feel free to adjust the implementation.

Copy link
Contributor Author

@ycombinator ycombinator Jan 15, 2021

Choose a reason for hiding this comment

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

Yeah, it's not perfect but I think this check here might have some good side-effects. In the asset test runner we check if we are dealing with a logs data stream and, if so, check that ingest pipeline assets have also been loaded. Similarly, whenever a new data stream type is added in the future we might need to have special handling for it somewhere in elastic-package. So being strict here about which data stream types elastic-package knows how to handle may be a good thing.

Case in point: I was checking the data stream manifest spec to see if we have defined the data stream type field as an enum and we have. However, while doing this I noticed that there is a data stream type we have not yet considered in elastic-package: traces. It was added for APM in elastic/package-spec#78. I'm guessing the APM team is not using elastic-package yet so they are not running into any issues with this type not being supported. I've created #223 to track adding support for this type in elastic-package.

@ycombinator
Copy link
Contributor Author

@mtojek I've addressed all your feedback. Please re-review when you get a chance. If the PR looks good to you, please merge it on my behalf as I'll be away from work for the next week. Otherwise I will address any further feedback when I'm back. Thanks!

@mtojek mtojek merged commit 2e65b64 into elastic:master Jan 18, 2021
@ycombinator ycombinator deleted the test-runner-asset branch January 25, 2021 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asset loading tests
3 participants