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

DataGenerator readability improvements #1103

Conversation

gregschohn
Copy link
Collaborator

Description

Rewrite the workload classes to use a fluent style w/ mixins so that the structure of what's being cons'ed together is much more immediately clear. Case in point, making the conversion took hours because 1) there weren't unit tests on the generator itself and 2) the one test that was there didn't have suitable logging - requests weren't printed out (which is probably why there what looked to be a bug in the docIds).

This also maintains the previous status-quo of the codebase in how to eschew static imports and shows how to favor mixins and for DSL-like (DSL-lite) applications.

  • Category Refactoring
  • Why these changes are required? First, to find out why there was pushback to removing static imports. Then I realized that I couldn't understand the code & decided that if this was going to be used more often, we needed it to be clearer and to have better patterns in place.
  • What is the old behavior before changes and new behavior after changes? docIds no longer contain a space.

Issues Resolved

Same sonar cleanup as this PR, which was merged before this one was opened for review.

Testing

gradle testing

Check List

  • New functionality includes testing
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.67%. Comparing base (d90a448) to head (c5b7b0f).
Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1103      +/-   ##
============================================
+ Coverage     80.66%   80.67%   +0.01%     
- Complexity     2892     2906      +14     
============================================
  Files           383      384       +1     
  Lines         14359    14358       -1     
  Branches        989      989              
============================================
+ Hits          11582    11584       +2     
+ Misses         2183     2181       -2     
+ Partials        594      593       -1     
Flag Coverage Δ
gradle-test 78.77% <100.00%> (+0.02%) ⬆️
python-test 90.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gregschohn gregschohn changed the title Add reindexFromSnapshotWorkerSize to cdk with default and maximum modes DataGenerator readability improvements Oct 24, 2024
@gregschohn gregschohn force-pushed the DataGeneratorReadabilityImprovements branch from eeff3be to b26db3c Compare October 24, 2024 14:39
@@ -6,7 +6,7 @@ appender.console.type = Console
appender.console.name = Console
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS}{UTC} %p %c{1.} [%t] %m%n
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Keeping thread identifiers is critical for multi-threaded code like this. It's necessary to correlate log lines together.


var docIdCounter = new AtomicInteger(0);
var allDocs = workload.createDocs(options.totalDocs)
.map(doc -> new DocumentReindexer.BulkDocSection(indexName + "_ " + docIdCounter.incrementAndGet(), doc.toString()))
.map(doc -> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would have liked to have used peek() here, but I didn't want to have to lose the sonarqube check for the whole file.

}
}
).log();
return new DocumentReindexer.BulkDocSection(indexName + "_" + docIdCounter.incrementAndGet(), doc.toString());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

notice that "_ " has been replaced with just "_"

@gregschohn gregschohn force-pushed the DataGeneratorReadabilityImprovements branch from b26db3c to 32e6139 Compare October 24, 2024 14:46
…the structure of what's being cons'ed together is much more immediately clear.

Fixed a bug in the docId having a space in it (I presume that was unintentional)

Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
@gregschohn gregschohn force-pushed the DataGeneratorReadabilityImprovements branch from 32e6139 to 9078313 Compare October 24, 2024 14:48
@gregschohn gregschohn marked this pull request as ready for review October 24, 2024 15:26
Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

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

The indenting around the ObjectNode construction is easier to read, thanks for making that change.

GEONAMES(Geonames::new),
HTTP_LOGS(HttpLogs::new),
NESTED(Nested::new),
NYC_TAXIS(NycTaxis::new);
Copy link
Member

Choose a reason for hiding this comment

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

Readme needs to be updated with these changed names, even if we parsed the enum case insensitively the underscore in NYC_TAXIS breaks the existing documentation. Good news, the help output is automatically updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thx - done

Copy link
Member

@chelma chelma left a comment

Choose a reason for hiding this comment

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

Easier to read now - thanks Greg!

Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
@gregschohn gregschohn merged commit e55e91a into opensearch-project:main Oct 24, 2024
14 checks passed
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.

3 participants