mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
attach http metrics directly to adapter part 2
This commit is contained in:
parent
d0efb5f07b
commit
553a493e5c
@ -41,11 +41,16 @@ import java.util.function.Function;
|
||||
@Service(value = DriverAdapter.class, selector = "http")
|
||||
public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
|
||||
|
||||
private final HttpMetrics httpMetrics;
|
||||
public final NBMetricHistogram statusCodeHistogram;
|
||||
|
||||
public HttpDriverAdapter(NBComponent parent, NBLabels labels) {
|
||||
super(parent, labels);
|
||||
this.httpMetrics=new HttpMetrics(this);
|
||||
this.statusCodeHistogram = create().histogram(
|
||||
"statuscode",
|
||||
Integer.parseInt(getComponentProp(NBComponentProps.HDRDIGITS).orElse("3")),
|
||||
MetricCategory.Payload,
|
||||
"A histogram of status codes received by the HTTP client"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,9 +91,4 @@ public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
|
||||
|
||||
return super.getConfigModel().add(HttpSpace.getConfigModel()).add(thisCfgModel);
|
||||
}
|
||||
|
||||
|
||||
public HttpMetrics getHttpMetrics() {
|
||||
return this.httpMetrics;
|
||||
}
|
||||
}
|
||||
|
@ -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.adapter.http.core;
|
||||
|
||||
import com.codahale.metrics.Histogram;
|
||||
import io.nosqlbench.adapter.http.HttpDriverAdapter;
|
||||
import io.nosqlbench.nb.api.components.core.NBComponentProps;
|
||||
import io.nosqlbench.nb.api.engine.metrics.instruments.MetricCategory;
|
||||
import io.nosqlbench.nb.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.nb.api.labels.NBLabels;
|
||||
|
||||
public class HttpMetrics implements NBLabeledElement {
|
||||
private final HttpDriverAdapter parentAdapter;
|
||||
final Histogram statusCodeHistogram;
|
||||
|
||||
public HttpMetrics(HttpDriverAdapter parentAdapter) {
|
||||
this.parentAdapter = parentAdapter;
|
||||
statusCodeHistogram = parentAdapter.create().histogram(
|
||||
"statuscode",
|
||||
Integer.parseInt(parentAdapter.getComponentProp(NBComponentProps.HDRDIGITS).orElse("3")),
|
||||
MetricCategory.Payload,
|
||||
"A histogram of status codes received by the HTTP client"
|
||||
);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return parentAdapter.getAdapterName() + "-metrics";
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return parentAdapter.getLabels();
|
||||
}
|
||||
}
|
@ -19,24 +19,13 @@ package io.nosqlbench.adapter.http.core;
|
||||
import io.nosqlbench.adapter.http.errors.InvalidResponseBodyException;
|
||||
import io.nosqlbench.adapter.http.errors.InvalidStatusCodeException;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
|
||||
import org.apache.logging.log4j.core.tools.picocli.CommandLine;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Spliterators;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class HttpOp implements CycleOp {
|
||||
|
||||
@ -75,7 +64,7 @@ public class HttpOp implements CycleOp {
|
||||
try {
|
||||
CompletableFuture<HttpResponse<String>> responseFuture = client.sendAsync(request, bodyreader);
|
||||
response = responseFuture.get(space.getTimeoutMillis(), TimeUnit.MILLISECONDS);
|
||||
space.getHttpMetrics().statusCodeHistogram.update(response.statusCode());
|
||||
space.statusCodeHistogram.update(response.statusCode());
|
||||
|
||||
if (ok_status != null) {
|
||||
if (!ok_status.matcher(String.valueOf(response.statusCode())).matches()) {
|
||||
|
@ -17,6 +17,8 @@
|
||||
package io.nosqlbench.adapter.http.core;
|
||||
|
||||
import io.nosqlbench.adapter.http.HttpDriverAdapter;
|
||||
import io.nosqlbench.nb.api.engine.metrics.DeltaHdrHistogramReservoir;
|
||||
import io.nosqlbench.nb.api.engine.metrics.instruments.NBMetricHistogram;
|
||||
import io.nosqlbench.nb.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.nb.api.labels.NBLabels;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
@ -43,13 +45,13 @@ public class HttpSpace implements NBLabeledElement {
|
||||
private final HttpDriverAdapter parentAdapter;
|
||||
private final String name;
|
||||
private final NBConfiguration cfg;
|
||||
public NBMetricHistogram statusCodeHistogram;
|
||||
private HttpConsoleFormats console;
|
||||
private HttpClient.Redirect followRedirects;
|
||||
private Duration timeout;
|
||||
private long timeoutMillis;
|
||||
private final HttpClient httpclient;
|
||||
private int hdrDigits;
|
||||
private HttpMetrics httpMetrics;
|
||||
private boolean diagnosticsEnabled;
|
||||
|
||||
|
||||
@ -58,6 +60,7 @@ public class HttpSpace implements NBLabeledElement {
|
||||
this.name = spaceName;
|
||||
this.cfg = cfg;
|
||||
applyConfig(cfg);
|
||||
this.statusCodeHistogram = parentAdapter.statusCodeHistogram;
|
||||
this.httpclient = newClient();
|
||||
}
|
||||
|
||||
@ -80,10 +83,9 @@ public class HttpSpace implements NBLabeledElement {
|
||||
);
|
||||
this.timeout = Duration.ofMillis(cfg.get("timeout", long.class));
|
||||
this.timeoutMillis = cfg.get("timeout", long.class);
|
||||
this.httpMetrics = parentAdapter.getHttpMetrics();
|
||||
|
||||
this.console = cfg.getOptional("diag").map(s -> HttpConsoleFormats.apply(s, this.console))
|
||||
.orElseGet(() -> HttpConsoleFormats.apply(null,null));
|
||||
.orElseGet(() -> HttpConsoleFormats.apply(null, null));
|
||||
|
||||
this.diagnosticsEnabled = console.isDiagnosticMode();
|
||||
|
||||
@ -106,10 +108,6 @@ public class HttpSpace implements NBLabeledElement {
|
||||
return name;
|
||||
}
|
||||
|
||||
public HttpMetrics getHttpMetrics() {
|
||||
return httpMetrics;
|
||||
}
|
||||
|
||||
public boolean isDiagnosticMode() {
|
||||
return diagnosticsEnabled;
|
||||
}
|
||||
@ -125,18 +123,15 @@ public class HttpSpace implements NBLabeledElement {
|
||||
.setDescription("Whether to follow redirects. Normal redirects are those which do not " +
|
||||
"redirect from HTTPS to HTTP.")
|
||||
)
|
||||
.add(Param.optional(List.of("diag","diagnostics"), String.class)
|
||||
.add(Param.optional(List.of("diag", "diagnostics"), String.class)
|
||||
.setDescription("Print extended diagnostics. This option has numerous" +
|
||||
" possible values. See the markdown docs for details. (nb help http)")
|
||||
)
|
||||
.add(Param.defaultTo("timeout", 1000L*60L*15L) // 15 minutes
|
||||
.add(Param.defaultTo("timeout", 1000L * 60L * 15L) // 15 minutes
|
||||
.setDescription("How long to wait for requests before timeout out. Default is forever."))
|
||||
.add(Param.defaultTo("hdr_digits", 4)
|
||||
.setDescription("number of digits of precision to keep in HDR histograms"))
|
||||
.asReadOnly();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user