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

NMS-16948: Add additional tags for latency resource #7443

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
Expand Up @@ -24,6 +24,9 @@
import org.opennms.netmgt.collection.support.DefaultTimeKeeper;
import org.opennms.netmgt.model.ResourcePath;

import java.util.HashMap;
import java.util.Map;

/**
* <p>CollectionResource interface.</p>
*
Expand Down Expand Up @@ -95,4 +98,9 @@ public interface CollectionResource extends ResourceIdentifier, CollectionVisita
*/
TimeKeeper getTimeKeeper();

// Can be used to add additional tags required by TimeSeries like Prometheus
default Map<String, String> getTags() {
return new HashMap<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class LatencyCollectionResource implements CollectionResource {
private final String m_location;
private final Map<AttributeGroupType, AttributeGroup> m_attributeGroups = Maps.newLinkedHashMap();

private final Map<String, String> m_tags = Maps.newHashMap();

/**
* <p>Constructor for LatencyCollectionResource.</p>
*
Expand All @@ -54,6 +56,13 @@ public LatencyCollectionResource(String serviceName, String ipAddress, String lo
m_location = location;
}

public LatencyCollectionResource(String serviceName, String ipAddress, String location, Map<String, String> tags) {
m_serviceName = serviceName;
m_ipAddress = ipAddress;
m_location = location;
m_tags.putAll(tags);
}

/**
* <p>getInstance</p>
*
Expand Down Expand Up @@ -197,4 +206,9 @@ public ResourcePath getParent() {
public TimeKeeper getTimeKeeper() {
return null;
}

@Override
public Map<String, String> getTags() {
return m_tags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Set<Tag> load(final CollectionResource resource) {

// create tags for categories
nodeOptional.ifPresent(onmsNode -> mapCategories(tags, onmsNode));
mapResourceTags(configuredMetaTags, tags, resource);
return tags;
});
}
Expand All @@ -125,6 +126,22 @@ private void mapCategories(final Set<Tag> tags, final OnmsNode node) {
}
}

private void mapResourceTags(final Map<String, String> configuredMetaTags, final Set<Tag> tags,
final CollectionResource resource) {

for (Map.Entry<String, String> entry : configuredMetaTags.entrySet()) {
if (entry.getValue().contains("resource:label") && resource.getInterfaceLabel() != null) {
tags.add(new ImmutableTag(entry.getKey(), resource.getInterfaceLabel()));
}
if (entry.getValue().contains("resource:node_label") && resource.getTags().get("node_label") != null) {
tags.add(new ImmutableTag(entry.getKey(), resource.getTags().get("node_label")));
}
if (entry.getValue().contains("resource:location") && resource.getTags().get("location") != null) {
tags.add(new ImmutableTag(entry.getKey(), resource.getTags().get("location")));
}
}
}

private Optional<OnmsNode> getNode(String nodeCriteria) {
if (nodeCriteria == null || nodeCriteria.trim().isEmpty()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -152,7 +153,11 @@ private CollectionSet getCollectionSet(MonitoredService service, Map<String, Num
// This happens whether or not storeByGroup is enabled.
// 2) If multiple entries are present, the DSs are created in the same order that they
// appear in the map
LatencyCollectionResource latencyResource = new LatencyCollectionResource(service.getSvcName(), service.getIpAddr(), service.getNodeLocation());
// Add labels to be used in time series that depends on labels
Map<String, String> tags = new HashMap<>();
tags.put("node_label", service.getNodeLabel());
tags.put("location", service.getNodeLocation());
LatencyCollectionResource latencyResource = new LatencyCollectionResource(service.getSvcName(), service.getIpAddr(), service.getNodeLocation(), tags);
for (final Entry<String, Number> entry : entries.entrySet()) {
final String ds = entry.getKey();
final Number value = entry.getValue() != null ? entry.getValue() : Double.NaN;
Expand Down
Loading