attach http adapter metrics directly to adapter instance

This commit is contained in:
Jonathan Shook 2024-07-31 14:22:05 -05:00
parent 2775715081
commit fd18bd2694
3 changed files with 26 additions and 19 deletions

View File

@ -16,16 +16,16 @@
package io.nosqlbench.adapter.http; package io.nosqlbench.adapter.http;
import io.nosqlbench.adapter.http.core.HttpFormatParser; import io.nosqlbench.adapter.http.core.*;
import io.nosqlbench.adapter.http.core.HttpOp; import io.nosqlbench.nb.api.components.core.NBComponentProps;
import io.nosqlbench.adapter.http.core.HttpOpMapper;
import io.nosqlbench.adapter.http.core.HttpSpace;
import io.nosqlbench.nb.api.config.standard.ConfigModel; import io.nosqlbench.nb.api.config.standard.ConfigModel;
import io.nosqlbench.nb.api.config.standard.Param; import io.nosqlbench.nb.api.config.standard.Param;
import io.nosqlbench.adapters.api.activityimpl.OpMapper; import io.nosqlbench.adapters.api.activityimpl.OpMapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter; import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter; import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache; import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
import io.nosqlbench.nb.api.engine.metrics.instruments.MetricCategory;
import io.nosqlbench.nb.api.engine.metrics.instruments.NBMetricHistogram;
import io.nosqlbench.nb.api.labels.NBLabels; import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.nb.api.components.core.NBComponent; import io.nosqlbench.nb.api.components.core.NBComponent;
import io.nosqlbench.nb.annotations.Service; import io.nosqlbench.nb.annotations.Service;
@ -41,8 +41,11 @@ import java.util.function.Function;
@Service(value = DriverAdapter.class, selector = "http") @Service(value = DriverAdapter.class, selector = "http")
public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> { public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
private final HttpMetrics httpMetrics;
public HttpDriverAdapter(NBComponent parent, NBLabels labels) { public HttpDriverAdapter(NBComponent parent, NBLabels labels) {
super(parent, labels); super(parent, labels);
this.httpMetrics=new HttpMetrics(this);
} }
@Override @Override
@ -54,7 +57,7 @@ public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
@Override @Override
public Function<String, ? extends HttpSpace> getSpaceInitializer(NBConfiguration cfg) { public Function<String, ? extends HttpSpace> getSpaceInitializer(NBConfiguration cfg) {
return spaceName -> new HttpSpace(getParent(), spaceName, cfg); return spaceName -> new HttpSpace(this, spaceName, cfg);
} }
@Override @Override
@ -84,4 +87,8 @@ public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
return super.getConfigModel().add(HttpSpace.getConfigModel()).add(thisCfgModel); return super.getConfigModel().add(HttpSpace.getConfigModel()).add(thisCfgModel);
} }
public HttpMetrics getHttpMetrics() {
return this.httpMetrics;
}
} }

View File

@ -17,33 +17,32 @@
package io.nosqlbench.adapter.http.core; package io.nosqlbench.adapter.http.core;
import com.codahale.metrics.Histogram; 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.engine.metrics.instruments.MetricCategory;
import io.nosqlbench.nb.api.labels.NBLabeledElement; import io.nosqlbench.nb.api.labels.NBLabeledElement;
import io.nosqlbench.nb.api.labels.NBLabels; import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.nb.api.components.core.NBComponent;
public class HttpMetrics implements NBLabeledElement { public class HttpMetrics implements NBLabeledElement {
private final NBComponent parent; private final HttpDriverAdapter parentAdapter;
private final HttpSpace space;
final Histogram statusCodeHistogram; final Histogram statusCodeHistogram;
public HttpMetrics(NBComponent parent, HttpSpace space) { public HttpMetrics(HttpDriverAdapter parentAdapter) {
this.parent = parent; this.parentAdapter = parentAdapter;
this.space = space; statusCodeHistogram = parentAdapter.create().histogram(
statusCodeHistogram = parent.create().histogram(
"statuscode", "statuscode",
space.getHdrDigits(), Integer.parseInt(parentAdapter.getComponentProp(NBComponentProps.HDRDIGITS).orElse("3")),
MetricCategory.Payload, MetricCategory.Payload,
"A histogram of status codes received by the HTTP client" "A histogram of status codes received by the HTTP client"
); );
} }
public String getName() { public String getName() {
return "http"+("default".equals(this.space.getSpaceName())?"": '-' + space.getSpaceName()); return parentAdapter.getAdapterName() + "-metrics";
} }
@Override @Override
public NBLabels getLabels() { public NBLabels getLabels() {
return space.getLabels(); return parentAdapter.getLabels();
} }
} }

View File

@ -16,6 +16,7 @@
package io.nosqlbench.adapter.http.core; package io.nosqlbench.adapter.http.core;
import io.nosqlbench.adapter.http.HttpDriverAdapter;
import io.nosqlbench.nb.api.labels.NBLabeledElement; import io.nosqlbench.nb.api.labels.NBLabeledElement;
import io.nosqlbench.nb.api.labels.NBLabels; import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.nb.api.config.standard.ConfigModel; import io.nosqlbench.nb.api.config.standard.ConfigModel;
@ -39,7 +40,7 @@ import java.util.Locale;
public class HttpSpace implements NBLabeledElement { public class HttpSpace implements NBLabeledElement {
private final static Logger logger = LogManager.getLogger(HttpSpace.class); private final static Logger logger = LogManager.getLogger(HttpSpace.class);
private final NBComponent parent; private final HttpDriverAdapter parentAdapter;
private final String name; private final String name;
private final NBConfiguration cfg; private final NBConfiguration cfg;
private HttpConsoleFormats console; private HttpConsoleFormats console;
@ -52,8 +53,8 @@ public class HttpSpace implements NBLabeledElement {
private boolean diagnosticsEnabled; private boolean diagnosticsEnabled;
public HttpSpace(NBComponent parent, String spaceName, NBConfiguration cfg) { public HttpSpace(HttpDriverAdapter parentAdapter, String spaceName, NBConfiguration cfg) {
this.parent = parent; this.parentAdapter = parentAdapter;
this.name = spaceName; this.name = spaceName;
this.cfg = cfg; this.cfg = cfg;
applyConfig(cfg); applyConfig(cfg);
@ -79,7 +80,7 @@ public class HttpSpace implements NBLabeledElement {
); );
this.timeout = Duration.ofMillis(cfg.get("timeout", long.class)); this.timeout = Duration.ofMillis(cfg.get("timeout", long.class));
this.timeoutMillis = cfg.get("timeout", long.class); this.timeoutMillis = cfg.get("timeout", long.class);
this.httpMetrics = new HttpMetrics(parent, this); this.httpMetrics = parentAdapter.getHttpMetrics();
this.console = cfg.getOptional("diag").map(s -> HttpConsoleFormats.apply(s, this.console)) this.console = cfg.getOptional("diag").map(s -> HttpConsoleFormats.apply(s, this.console))
.orElseGet(() -> HttpConsoleFormats.apply(null,null)); .orElseGet(() -> HttpConsoleFormats.apply(null,null));