diff --git a/helm/examples/metrics/README.md b/helm/examples/metrics/README.md index 9c631aa69df..bf93e4d2dee 100644 --- a/helm/examples/metrics/README.md +++ b/helm/examples/metrics/README.md @@ -235,7 +235,7 @@ To create an index with dynamic mapping, use the following object, or other mean The object names beginning with "hpcc_metric_" represent the mappings for the three affected hpcc metrics types. The _match_ value for each defines the expected suffix for each HPCC metric value, based on type, when metrics -are reported and indexed. The object names above are the default values useed by the sink. The index can be +are reported and indexed. The object names above are the default values used by the sink. The index can be configured with different object names (for environment flexibility), but the object names must be provided to the sink as additional configuration settings (defined below). @@ -326,7 +326,7 @@ Add the following to the environment.xml configuration file (note that some valu + certificateFilePath=""> Get(endpoint.c_str(), elasticHeaders); + + if (res == nullptr) + { + WARNLOG("ElasticMetricSink: Unable to connect to ElasticSearch host %s", elasticHostUrl.str()); + return false; + } + if (res->status != 200) { - WARNLOG("ElasticMetricSink: Unable to retrieve index mapping for index %s", indexName.str()); + WARNLOG("ElasticMetricSink: Error response status = %d, unable to retrieve mapping for index '%s'", res->status, indexName.str()); return false; } @@ -186,21 +196,21 @@ bool ElasticMetricSink::getDynamicMappingSuffixesFromIndex(const IPropertyTree * auto indexConfig = data[indexName.str()]; if (indexConfig.is_null()) { - WARNLOG("ElasticMetricSink: Mapping section for Index '%s' does not exist", indexName.str()); + WARNLOG("ElasticMetricSink: Unable to load configuration for Index '%s'", indexName.str()); return false; } auto mappings = indexConfig["mappings"]; if (mappings.is_null()) { - WARNLOG("ElasticMetricSink: Index %s does not have a 'mappings' section", indexName.str()); + WARNLOG("ElasticMetricSink: Required 'mappings' section does not exist in Index '%s'", indexName.str()); return false; } auto dynamicTemplates = mappings["dynamic_templates"]; if (dynamicTemplates.is_null()) { - WARNLOG("ElasticMetricSink: Index %s does not have a 'dynamic_templates' section", indexName.str()); + WARNLOG("ElasticMetricSink: Required 'dynamic_templates' section does not exist in Index '%s'", indexName.str()); return false; } @@ -215,9 +225,9 @@ bool ElasticMetricSink::getDynamicMappingSuffixesFromIndex(const IPropertyTree * { auto const &mappingName = it.first; auto kvPairs = it.second; + auto const &matchValue = kvPairs["match"]; if (mappingName == countSuffixMappingName.str()) { - auto const &matchValue = kvPairs["match"]; if (!convertPatternToSuffix(matchValue.get().c_str(), countMetricSuffix)) { WARNLOG("ElasticMetricSink: Invalid count suffix pattern"); @@ -226,7 +236,6 @@ bool ElasticMetricSink::getDynamicMappingSuffixesFromIndex(const IPropertyTree * } else if (mappingName == histogramSuffixMappingName.str()) { - auto const &matchValue = kvPairs["match"]; if (!convertPatternToSuffix(matchValue.get().c_str(), histogramMetricSuffix)) { WARNLOG("ElasticMetricSink: Invalid histogram suffix pattern"); @@ -235,7 +244,6 @@ bool ElasticMetricSink::getDynamicMappingSuffixesFromIndex(const IPropertyTree * } else if (mappingName == gaugeSuffixMappingName.str()) { - auto const &matchValue = kvPairs["match"]; if (!convertPatternToSuffix(matchValue.get().c_str(), gaugeMetricSuffix)) { WARNLOG("ElasticMetricSink: Invalid gauge suffix pattern"); @@ -291,6 +299,10 @@ void ElasticMetricSink::intializeElasticClient() // Add cert path if needed if (!certificateFilePath.isEmpty()) pClient->set_ca_cert_path(certificateFilePath.str()); + + pClient->set_connection_timeout(5); + pClient->set_read_timeout(5); + pClient->set_write_timeout(5); } @@ -318,9 +330,15 @@ bool ElasticMetricSink::validateIndex() endpoint.append("/").append(indexName.str()); auto res = pClient->Get(endpoint.c_str(), elasticHeaders); - if (res->status != 200) + if (res == nullptr) + { + WARNLOG("ElasticMetricSink: Unable to connect to ElasticSearch host %s", elasticHostUrl.str()); + return false; + } + + else if (res->status != 200) { - WARNLOG("ElasticMetricSink: Index %s does not exist", indexName.str()); + WARNLOG("ElasticMetricSink: Error response status = %d accessing Index '%s'", res->status, indexName.str()); return false; } return true; diff --git a/system/metrics/sinks/elastic/elasticSink.hpp b/system/metrics/sinks/elastic/elasticSink.hpp index 4caa454bdff..0da499b1437 100644 --- a/system/metrics/sinks/elastic/elasticSink.hpp +++ b/system/metrics/sinks/elastic/elasticSink.hpp @@ -1,5 +1,5 @@ /*############################################################################## - HPCC SYSTEMS software Copyright (C) 2025 HPCC Systems®. + HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. 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