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

SQL: change the audit log file rolling behavior in tests #34909

Merged
merged 3 commits into from
Feb 8, 2019

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Oct 26, 2018

This is a fix attempt for #33987, where tests fails because the audit log file is empty, which can happen when the file is rolled over at midnight. If reading the file happens during the rollover the file would be empty (which shouldn't actually happen).

The fix is to extend the rolling over period to 2 days (default is one). The provided log4j2.properties file is overriding the default one. Elasticsearch should be able to pickup additional log4j files from /config as long as they live in the /config folder in different directories. Those should be merged in a final log4j config. extraConfigFile doesn't work with directories though.

@astefan astefan added >test Issues or PRs that are addressing/adding tests :Analytics/SQL SQL querying labels Oct 26, 2018
@astefan astefan requested review from costin and nik9000 October 26, 2018 14:44
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@costin
Copy link
Member

costin commented Oct 26, 2018

LGTM. Too bad the configuration file has to be this big.

@@ -51,6 +54,9 @@ subprojects {
setting 'xpack.license.self_generated.type', 'trial'
// Setup roles used by tests
extraConfigFile 'roles.yml', '../roles.yml'
// Change the log4j configuration for audit logging file, more specifically make it roll over every 2 days
// Some tests do read the audit log file and do not account for the daily (default) rollover
extraConfigFile 'log4j2.properties', '../log4j2.properties'
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a task to copy and modify the original from distributions/src/config ?
You can reference the location as "${project(':distributions').projectDir}/src/config/log4j2.properties, have a copy task to copy this one file and then have a doLast to modify it as you would like.

@alpar-t alpar-t added the :Delivery/Build Build or test infrastructure label Oct 29, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@astefan
Copy link
Contributor Author

astefan commented Oct 29, 2018

@costin @atorok I've changed the approach and I'm taking Elasticsearch' log4j2 config (without x-pack settings) and combining it with the x-pack specific ones and then change only one line from the resulting file. Finally, overriding the one used in tests with the combined one above.

Copy link
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

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

I left some minor comments.
I think this looks ok now.
Would probably be better to offer a hook in clusterformation to be able to edit the log config,
especially if more places in the build will require it, but since we are going to replace it i'm hesitant to do that now.

@@ -23,14 +23,30 @@ subprojects {
testCompile "org.elasticsearch.plugin:x-pack-core:${version}"
}

task changeAuditLoggingRollingPolicy {
def toConcatenate = files("${project(':distribution').projectDir}/src/config/log4j2.properties", "${project(':x-pack').projectDir}/plugin/core/src/main/config/log4j2.properties")
Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer specifying types explicitly instead of def. This one would be a FileCollection.

task changeAuditLoggingRollingPolicy {
def toConcatenate = files("${project(':distribution').projectDir}/src/config/log4j2.properties", "${project(':x-pack').projectDir}/plugin/core/src/main/config/log4j2.properties")
def outputFileName = "${buildDir}/log4j2.properties"
def output = new File(outputFileName)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use file() or project.file() instead of new File in Gradle as the former always resolves relative paths to project dir.
It won't make a difference here, but a best practice that we would like to follow.

@astefan
Copy link
Contributor Author

astefan commented Oct 30, 2018

@atorok Addressed comments. Thank you for reviewing.

@jasontedor
Copy link
Member

Why not consume all log files in the assertion, instead of making this integration test cluster have a special configuration file that deviates from default behavior?

@astefan
Copy link
Contributor Author

astefan commented Oct 30, 2018

@jasontedor did it like this because the way we consume those files is not relevant to the test itself, but the content of the file(s) is. And accounting for files rollover complicates the test too much.

@jasontedor
Copy link
Member

Yet it complicates the build.gradle instead, which is far removed from the impacted tests.

@henriquegoncalves98
Copy link
Contributor

hey, how can i test a single class in the terminal?

@danielmitterdorfer
Copy link
Member

@astefan I also think the approach that @jasontedor has suggested is worthwhile pursuing. By consuming all audit log files in the test we can stick to the default logging configuration. Can you please take a stab to implement this?

@astefan
Copy link
Contributor Author

astefan commented Jan 29, 2019

@danielmitterdorfer yes, I fully agree, and I didn't forget about this issue, but I've been caught into more urgent tasks. Once I get the chance, I'll have another look at this issue. It's on my virtual TO-DO list.

@danielmitterdorfer
Copy link
Member

Great, thank you Andrei!

@astefan astefan requested review from matriv and removed request for nik9000 February 7, 2019 17:54
Copy link
Contributor

@matriv matriv 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 a comment

@SuppressForbidden(reason="security doesn't work with mock filesystem")
private static Path lookupRolledOverAuditLog() {
String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile");
if (null == auditLogFileString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

or empty?

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

@astefan
Copy link
Contributor Author

astefan commented Feb 8, 2019

@elasticmachine run elasticsearch-ci/1 elasticsearch-ci/2 elasticsearch-ci/default-distro

@astefan
Copy link
Contributor Author

astefan commented Feb 8, 2019

@elasticmachine run elasticsearch-ci/2
@elasticmachine run elasticsearch-ci/default-distro

@astefan astefan merged commit 75cb6b3 into elastic:master Feb 8, 2019
@astefan astefan added backport pending and removed :Delivery/Build Build or test infrastructure labels Feb 8, 2019
astefan added a commit that referenced this pull request Feb 8, 2019
astefan added a commit that referenced this pull request Feb 8, 2019
astefan added a commit that referenced this pull request Feb 8, 2019
@astefan astefan deleted the 33987_test_fix branch February 8, 2019 16:34
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 8, 2019
* master:
  Mute AnalysisModuleTests#testStandardFilterBWC (elastic#38636)
  add geotile_grid ref to asciidoc (elastic#38632)
  Enable Dockerfile from artifacts.elastic.co (elastic#38552)
  Mute FollowerFailOverIT testFailOverOnFollower (elastic#38634)
  Account for a possible rolled over file while reading the audit log file (elastic#34909)
  Mute failure in InternalEngineTests (elastic#38622)
  Fix Issue with Concurrent Snapshot Init + Delete (elastic#38518)
  Refactor ZonedDateTime.now in millis resolution (elastic#38577)
  Mute failing WatchStatusIntegrationTests (elastic#38621)
  Mute failing  ApiKeyIntegTests (elastic#38614)
  [DOCS] Add warning about bypassing ML PUT APIs (elastic#38509)
  Add 7.1 and 8.0 version constants to master (elastic#38514)
jasontedor added a commit to liketic/elasticsearch that referenced this pull request Feb 10, 2019
* master: (1159 commits)
  Fix timezone fallback in ingest processor (elastic#38407)
  Avoid polluting download stats on builds (elastic#38660)
  SQL: Prevent grouping over grouping functions (elastic#38649)
  SQL: Relax StackOverflow circuit breaker for constants (elastic#38572)
  [DOCS] Fixes broken migration links (elastic#38655)
  Drop support for the low-level REST client on JDK 7 (elastic#38540)
  [DOCS] Adds placeholders for v8 highlights, breaking changes, release notes (elastic#38641)
  fix dissect doc "ip" --> "clientip" (elastic#38545)
  Concurrent file chunk fetching for CCR restore (elastic#38495)
  make DateMathIndexExpressionsIntegrationIT more resilient (elastic#38473)
  SQL: Replace joda with java time (elastic#38437)
  Add fuzziness example (elastic#37194) (elastic#38648)
  Mute AnalysisModuleTests#testStandardFilterBWC (elastic#38636)
  add geotile_grid ref to asciidoc (elastic#38632)
  Enable Dockerfile from artifacts.elastic.co (elastic#38552)
  Mute FollowerFailOverIT testFailOverOnFollower (elastic#38634)
  Account for a possible rolled over file while reading the audit log file (elastic#34909)
  Mute failure in InternalEngineTests (elastic#38622)
  Fix Issue with Concurrent Snapshot Init + Delete (elastic#38518)
  Refactor ZonedDateTime.now in millis resolution (elastic#38577)
  ...
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 11, 2019
* master: (27 commits)
  Mute AnalysisModuleTests#testStandardFilterBWC (elastic#38636)
  add geotile_grid ref to asciidoc (elastic#38632)
  Enable Dockerfile from artifacts.elastic.co (elastic#38552)
  Mute FollowerFailOverIT testFailOverOnFollower (elastic#38634)
  Account for a possible rolled over file while reading the audit log file (elastic#34909)
  Mute failure in InternalEngineTests (elastic#38622)
  Fix Issue with Concurrent Snapshot Init + Delete (elastic#38518)
  Refactor ZonedDateTime.now in millis resolution (elastic#38577)
  Mute failing WatchStatusIntegrationTests (elastic#38621)
  Mute failing  ApiKeyIntegTests (elastic#38614)
  [DOCS] Add warning about bypassing ML PUT APIs (elastic#38509)
  Add 7.1 and 8.0 version constants to master (elastic#38514)
  ML: update set_upgrade_mode, add logging (elastic#38372)
  bad formatted JSON object (elastic#38515) (elastic#38525)
  Fix HistoryIntegrationTests timestamp comparsion (elastic#38505)
  SQL: Fix issue with IN not resolving to underlying keyword field (elastic#38440)
  Fix the clock resolution to millis in ScheduledEventTests (elastic#38506)
  Enable BWC after backport recovering leases (elastic#38485)
  Collapse retention lease integration tests (elastic#38483)
  TransportVerifyShardBeforeCloseAction should force a flush (elastic#38401)
  ...
tvernum pushed a commit to tvernum/elasticsearch that referenced this pull request Mar 4, 2019
tvernum added a commit that referenced this pull request Mar 4, 2019
…ile (#39615)

Backport of: #34909

Co-authored-by: Andrei Stefan <astefan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >test Issues or PRs that are addressing/adding tests v6.7.0 v7.0.0-beta1 v7.2.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants