From cd1fc60a878792b94fb1ef8497de68d240141109 Mon Sep 17 00:00:00 2001 From: Ken Rowland Date: Tue, 5 Nov 2024 12:21:21 -0500 Subject: [PATCH] Addressed additional comments --- .../metrics/elasticsearch_metrics.yaml | 2 +- system/metrics/sinks/elastic/elasticSink.cpp | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/helm/examples/metrics/elasticsearch_metrics.yaml b/helm/examples/metrics/elasticsearch_metrics.yaml index 0ade007606e..c87652c4b17 100644 --- a/helm/examples/metrics/elasticsearch_metrics.yaml +++ b/helm/examples/metrics/elasticsearch_metrics.yaml @@ -1,5 +1,5 @@ # -# Defines a elastic sink for reporting metrics to an ElasticSearch instance +# Defines an elastic sink for reporting metrics to an ElasticSearch instance # Settings: # type - sink type (must be elastic for ElasticSearch support) # name - name for the sink instance diff --git a/system/metrics/sinks/elastic/elasticSink.cpp b/system/metrics/sinks/elastic/elasticSink.cpp index fea060f468d..6a53349d235 100644 --- a/system/metrics/sinks/elastic/elasticSink.cpp +++ b/system/metrics/sinks/elastic/elasticSink.cpp @@ -48,17 +48,19 @@ ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSet StringBuffer hostPort; Owned pHostConfigTree = pSettingsTree->getPropTree("host"); - - pHostConfigTree->getProp("@name", hostName); - - if (!pHostConfigTree->getProp("@protocol", hostProtocol)) + if (pHostConfigTree) { - hostProtocol.append("https"); - } + pHostConfigTree->getProp("@name", hostName); - if (!pHostConfigTree->getProp("@port", hostPort)) - { - hostPort.append("9200"); + if (!pHostConfigTree->getProp("@protocol", hostProtocol)) + { + hostProtocol.append("https"); + } + + if (!pHostConfigTree->getProp("@port", hostPort)) + { + hostPort.append("9200"); + } } if (!hostName.isEmpty() && !hostPort.isEmpty() && !hostProtocol.isEmpty()) @@ -67,16 +69,21 @@ ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSet } else { - WARNLOG("ElasticMetricSink: Host configuration is invalid"); + WARNLOG("ElasticMetricSink: Host configuration missing or invalid"); } Owned pIndexConfigTree = pSettingsTree->getPropTree("index"); - pSettingsTree->getProp("@name", indexName); + if (pIndexConfigTree) + { + pSettingsTree->getProp("@name", indexName); + } + if (indexName.isEmpty()) { - WARNLOG("ElasticMetricSink: Index configuration is invalid"); + WARNLOG("ElasticMetricSink: Index configuration missing or invalid"); } + // Both a host url and an index name are required configurationValid = !elasticHostUrl.isEmpty() && !indexName.isEmpty();