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

feat(wire.CloudPublisher): Set as body a property removing it from metrics #4328

Merged
merged 5 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2016, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2016, 2023 Eurotech and/or its affiliates and others

This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -47,6 +47,15 @@
default=""
description="If set to a non empty value, the publisher will set the message body to the value of the provided STRING or BYTE_ARRAY metric.">
</AD>

<AD id="remove.body.from.metrics"
name="Remove body envelope property from metrics"
type="Boolean"
cardinality="0"
required="true"
default="false"
description="Set true to remove the metric that is sent as body of the message.">
</AD>
</OCD>

<Designate pid="org.eclipse.kura.wire.CloudPublisher" factoryPid="org.eclipse.kura.wire.CloudPublisher">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -60,8 +60,6 @@ public final class CloudPublisher implements WireReceiver, ConfigurableComponent

private static final Logger logger = LogManager.getLogger(CloudPublisher.class);

private static final String ASSET_NAME_PROPERTY_KEY = "assetName";

private CloudPublisherOptions cloudPublisherOptions;

private volatile WireHelperService wireHelperService;
Expand Down Expand Up @@ -235,6 +233,12 @@ private void publishBody(final KuraPayload kuraPayload, final Map<String, TypedV
} catch (final Exception e) {
logger.warn("failed to publish body", e);
}

boolean isRemoveBodyPropertyFromMetrics = this.cloudPublisherOptions.getRemoveBodyPropertyFromMetrics();

if (isRemoveBodyPropertyFromMetrics) {
kuraPayload.removeMetric(bodyProperty);
}
}

private KuraPosition getPosition() {
Expand Down Expand Up @@ -286,6 +290,14 @@ private Map<String, Object> buildKuraMessageProperties(final WireRecord wireReco
for (String s : l) {
properties.put(s, wireRecordProps.get(s).getValue());
}

Optional<String> bodyProperty = this.cloudPublisherOptions.getBodyProperty();
boolean isRemoveBodyPropertyFromMetrics = this.cloudPublisherOptions.getRemoveBodyPropertyFromMetrics();

if (bodyProperty.isPresent() && isRemoveBodyPropertyFromMetrics) {
properties.remove(bodyProperty.get());
}

return properties;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -32,6 +32,7 @@ final class CloudPublisherOptions {

private static final String CONF_POSITION = "publish.position";
private static final String CONF_BODY_PROPERTY = "set.body.from.property";
private static final String CONF_REMOVE_BODY_PROPERTY = "remove.body.from.metrics";

private final Map<String, Object> properties;

Expand Down Expand Up @@ -82,4 +83,8 @@ Optional<String> getBodyProperty() {

return Optional.of(property);
}

boolean getRemoveBodyPropertyFromMetrics() {
return (boolean) this.properties.getOrDefault(CONF_REMOVE_BODY_PROPERTY, false);
}
}
Loading