Http and S3 plugns

This commit is contained in:
Mark Wolters 2023-10-05 14:39:19 -04:00 committed by Jonathan Shook
parent 2771ef60e9
commit 6e496f8e7b
7 changed files with 24 additions and 191 deletions

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.extensions.http;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
@Service(value = ScriptingExtensionPluginInfo.class, selector = "http")
public class HttpPluginData implements ScriptingExtensionPluginInfo<HttpPlugin> {
@Override
public String getDescription() {
return "use http get and post in scripts";
}
@Override
public HttpPlugin getExtensionObject(final Logger logger, final NBComponent baseComponent) {
return new HttpPlugin();
}
}

View File

@ -1,26 +0,0 @@
http extension
==============
Allow access to HTTP URLs from within scripts, supporting both basic
get and post methods. In all cases, the returned type is the full
response object, from which the body content can be accessed.
## Examples
Get content from a URL into a string variable:
```
var response= http.get("http://google.com/")
```
Post an empty body to a URL, useful for state-changing calls where
all of the control data is in the URL:
```
var response= http.post("http://some.server/path/to/resource?query=foobarbaz")
```
Post content to a URL, specifying the URL, content value, and content type:
```
var response= http.post("http://some.server/path/to/resource", "this is the data", "text/plain");
```

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.extensions.s3uploader;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.api.metadata.ScenarioMetadata;
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
@Service(value = ScriptingExtensionPluginInfo.class, selector = "s3")
public class S3UploaderPluginData implements ScriptingExtensionPluginInfo<S3Uploader>, ScenarioMetadataAware {
private ScenarioMetadata scenarioMetadata;
@Override
public String getDescription() {
return "Allow for uploading or downloading a directory from S3";
}
@Override
public S3Uploader getExtensionObject(final Logger logger, final NBComponent baseComponent) {
final S3Uploader uploader = new S3Uploader(logger, baseComponent);
ScenarioMetadataAware.apply(uploader, this.scenarioMetadata);
return uploader;
}
@Override
public void setScenarioMetadata(final ScenarioMetadata metadata) {
scenarioMetadata = metadata;
}
}

View File

@ -1,68 +0,0 @@
S3 extension
==============
Allow uploading of a local directory on the default filesystem
to an S3 bucket, using an S3 URI to specify the bucket, location, and so on.
The URL is specified in the standard S3 format, such as:
1. `s3://mybucket/mypath-as-a-key/with-any-level-of-depth`
2. `s3://myuser:mypass@mybucket/mypath-as-a-key/with-any-level-of-depth`
In addition, any tokens which are supported by the standard NoSQLBench
token substitution mechanism will be used to construct a URL at the time
of usage. These forms include the following:
- Scenario Metadata - There are several key fields initialized for a scenario which can be used as common
reference points. These occlude the environment variables of the same name. These are:
- SESSION_NAME - The name auto-generated for a session, used in the logfile names, and so on.
- SYSTEM_ID - The string form of the most canonically identifying IP address, excluding
known symbolic interface names (docker*, for example) and all localhost addresses.
- SYSTEM_FINGERPRINT - a stable and anonymized identifier for a given system. This will be
stable as long as the networking configuration does not change.
- System Properties
- Any parameter in `$word1.word2...` form -- any multi-part variable name with separating dots
is taken as a system property to the JVM. These are expanded in place. Both `$word1.word2`
and `${word1.word2}` patterns are supported, whereas the latter is more strict and thus safer.
- Environment Variables
- As with System Properties, environment variable form the shell are also supported, as long
as they do not include a dot.
- Temporal Fields from the Scenario start time
- Any field specifier that you can use with the temporal types in Java's standard String.
format can be used. The reference time for these is always the scenario start time.
- Example: The default session name template looks like `scenario_%tY%tm%td_%tH%tM%tS_%tL`
## Examples
```
// If you have local logical identifiers in your scenario script which you want
// to templatize into your upload paths, you can provide your own js object
// as the third parameter
s3.uploadDirToUrlTokenized(
'metrics',
's3://test-results/${HOSTNAME}/${testid}-${testversion}/metrics',
{
'testid':'20210343',
'testversion':'v2'
}
);
// Otherwise, use the two-parameter version:
s3.uploadDirToUrl('metrics','s3://test-results/${HOSTNAME}/metrics');
```
## Post-Hoc upload
Scripting extensions only run if the scenario is not halted before they are invoked
in the main scenario script. If you want to ensure that this one runs after a test,
regardless of when or why the test stopped, it is possible to wrap it within
a shutdown hook which will run after scenario completion.
This is an example of how to do so:
```
shutdown.addShutdownHook('upload_metrics', function f() {
s3.uploadDirToUrl('metrics','s3://test-results/${HOSTNAME}/metrics');
});
```

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -12,9 +12,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.nosqlbench.engine.extensions.http;
package io.nosqlbench.api.http;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import java.io.IOException;
import java.net.URI;
@ -22,9 +26,13 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class HttpPlugin {
public class HttpPlugin extends NBBaseComponent {
private final HttpClient client = HttpClient.newHttpClient();
public HttpPlugin(NBComponent parentComponent) {
super(parentComponent);
}
public HttpResponse<String> get(String url) throws IOException, InterruptedException {
HttpRequest.Builder builder = HttpRequest.newBuilder();
URI uri = URI.create(url);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.nosqlbench.engine.extensions.s3uploader;
package io.nosqlbench.api.s3uploader;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.transfer.MultipleFileUpload;
@ -27,9 +28,9 @@ import io.nosqlbench.api.metadata.ScenarioMetadataAware;
import io.nosqlbench.api.system.NBEnvironment;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.script.ScriptContext;
import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Files;
@ -38,14 +39,12 @@ import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
public class S3Uploader implements ScenarioMetadataAware {
private final Logger logger;
private final NBComponent baseComponent;
public class S3Uploader extends NBBaseComponent implements ScenarioMetadataAware {
private ScenarioMetadata scenarioMetadata;
private final static Logger logger = LogManager.getLogger(S3Uploader.class);
public S3Uploader(Logger logger, NBComponent baseComponent) {
this.logger = logger;
this.baseComponent = baseComponent;
public S3Uploader(NBComponent baseComponent) {
super(baseComponent);
}
/**

View File

@ -30,6 +30,7 @@ import io.nosqlbench.api.engine.metrics.reporters.MetricInstanceFilter;
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporterComponent;
import io.nosqlbench.api.histo.HdrHistoLog;
import io.nosqlbench.api.histo.HistoStats;
import io.nosqlbench.api.http.HttpPlugin;
import io.nosqlbench.api.optimizers.BobyqaOptimizerInstance;
import io.nosqlbench.api.files.FileAccess;
import io.nosqlbench.api.labels.NBLabels;
@ -144,6 +145,10 @@ public class NBBuilders {
return new HistoStats(component);
}
public HttpPlugin httpPlugin(NBComponent component) {
return new HttpPlugin(component);
}
public static class CsvOutputWriterBuilder {
//CsvOutputPluginWriter(NBComponent component, String filename, String... headers) {
private final NBComponent component;