-
Notifications
You must be signed in to change notification settings - Fork 304
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
HPCC-32909 Retrieve index settings from ElasticSearch server #19377
base: master
Are you sure you want to change the base?
Conversation
Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-32909 Jirabot Action Result: |
helm/examples/metrics/README.md
Outdated
In all cases, the configuration of the sink must match that of the dynamic mappings in the index. | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"useed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
helm/examples/metrics/README.md
Outdated
@@ -306,10 +325,11 @@ Add the following to the environment.xml configuration file (note that some valu | |||
<metrics name="mymetricsconfig"> | |||
<sinks name="myelasticsink" type="elastic"> | |||
<settings period="30" ignoreZeroMetrics="1"> | |||
<host domain="<domainname>" port="<port>" protocol="http|https"> | |||
<host domain="<domainname>" port="<port>" protocol="http|https" | |||
certificateFilePath="/home/krowland/elastic/cert/http_ca.crt"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid using your username from this example. I'd opt for something obvious such as "myusername"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced. Question: is there a location on the node where the cert file can be placed so that the sink does not have to specify the path? Could be part of configuring a cluster to use ElasticSearch.
countMetricSuffix: count | ||
gaugeMetricSuffix: gauge | ||
histogramMetricSuffix: histogram | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new line prob should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -1,5 +1,5 @@ | |||
/*############################################################################## | |||
HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. | |||
HPCC SYSTEMS software Copyright (C) 2025 HPCC Systems®. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this was created last year, date shouldn't be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored to 2024
@@ -16,21 +16,6 @@ | |||
#include "jsecrets.hpp" | |||
#include "jencrypt.hpp" | |||
|
|||
//including cpp-httplib single header file REST client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change directly related to the issue addressed by this jira?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
httplib::Result res = pClient->Get(endpoint.c_str(), elasticHeaders); | ||
if (res->status != 200) | ||
{ | ||
WARNLOG("ElasticMetricSink: Unable to retrieve index mapping for index %s", indexName.str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if httplib::Result provides a message as well, it should be reported as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httplib result includes a response body (html), but that is likely too long to log. I added the return status code. If we find during testing that additional information from the body is needed, we can review and determine the best way to parse the body and add relevant data to the log.
auto indexConfig = data[indexName.str()]; | ||
if (indexConfig.is_null()) | ||
{ | ||
WARNLOG("ElasticMetricSink: Mapping section for Index '%s' does not exist", indexName.str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does one recover from this? Provide useful information to the target audience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no recovery. The mapping section is required. "Unable to continue" can be added (or similar). This is where Ops would need to properly configure the index. Should a log message tell the target audience to refer to a specific document?
WARNLOG("ElasticMetricSink: Invalid gauge suffix pattern"); | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else? report unexpected mapping if encountered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other mappings can exist. We only look for the ones of interest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see if this was addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment I forgot to release. It is not an error for other mappings to exist.
@@ -187,37 +187,41 @@ sink will report metrics from all components to the same index. Therefore, the | |||
index must be configured to receive metrics from all components. | |||
|
|||
#### Index Configuration | |||
The index must be created in ElasticSearch before metrics can be reported to it. The name is passed | |||
to the sink as a configuration setting. The index must be created with the following settings: | |||
The sink requires the index to be created and configured fully in ElasticSearch in order for the sink to report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README updates are meant to be helpful, but I found the wording confusing. It might be worth seeking feedback from the doc guys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the information here is beyond the intent of the README. I think we need to consider some separate documentation for each sink (could be in same doc). I'd like to address that with Stu and Jim. But for now, I wanted to try and capture the information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up comments...
@@ -38,6 +37,10 @@ ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSet | |||
configurationValid = true; | |||
PROGLOG("ElasticMetricSink: Loaded and configured"); | |||
} | |||
else | |||
{ | |||
PROGLOG("ElasticMetricSink: Unable to complete initialization, sink not collecting"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a warning rather than just progress log. Also, if we know why the problem occurred (either host or index config invalid/missing) we should report it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to WARNLOG. If init fails, there will be at least one log message prior to this one with the specific reason.
@@ -175,9 +177,16 @@ bool ElasticMetricSink::getDynamicMappingSuffixesFromIndex(const IPropertyTree * | |||
std::string endpoint; | |||
endpoint.append("/").append(indexName.str()).append("/_mapping"); | |||
httplib::Result res = pClient->Get(endpoint.c_str(), elasticHeaders); | |||
|
|||
if (res == nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per online search:
Error Handling:
If the Result is null, it indicates that the request failed. You can use httplib::Error enum to get more details about the error.
and I found this sample error handling pattern:
if (res && res->status == 200)
{
std::cout << res->body << "\n";
}
else
{
auto err = res.error();
std::cout << httplib::to_string(err) << "\n";
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added code to capture the error, but there is not httplib::to_string function, so just the number is displayed.
@@ -291,6 +298,10 @@ void ElasticMetricSink::intializeElasticClient() | |||
// Add cert path if needed | |||
if (!certificateFilePath.isEmpty()) | |||
pClient->set_ca_cert_path(certificateFilePath.str()); | |||
|
|||
pClient->set_connection_timeout(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default timeout values are always difficult and usually don't cover most situations. A couple of suggestions:
- make these configurable
- connect and read/write timeout values should be independent, 5 sec connection timeout might be reasonable, but successful reads/writes might take longer than 5 secs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added configurable host parameters. Note that after the initial read, we will only be doing writes to index metrics.
{ | ||
std::string endpoint; | ||
endpoint.append("/").append(indexName.str()); | ||
auto res = pClient->Get(endpoint.c_str(), elasticHeaders); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is pClient only used to extract index info? if we intent to use it for other functionality, the above timeout values might not be reasonable.
@@ -318,9 +329,15 @@ bool ElasticMetricSink::validateIndex() | |||
endpoint.append("/").append(indexName.str()); | |||
auto res = pClient->Get(endpoint.c_str(), elasticHeaders); | |||
|
|||
if (res->status != 200) | |||
if (res == nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above suggestion on libhttp err handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional handling added.
} | ||
|
||
|
||
bool ElasticMetricSink::prepareToStartCollecting() | ||
bool ElasticMetricSink::convertPatternToSuffix(const char *pattern, StringBuffer &suffix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be static, or does it need to be a member? also, is it const?
WARNLOG("ElasticMetricSink: Invalid gauge suffix pattern"); | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see if this was addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added code to query configured index on ElasticSearch server for dynamic mapping template match values for hpcc metric type suffixes. Signed-Off-By: Kenneth Rowland [email protected]
@ghalliday please merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any problems.
{ | ||
StringBuffer countSuffixMappingName; | ||
if (!pIndexConfigTree->getProp("@countSuffixMappingName", countSuffixMappingName)) | ||
countSuffixMappingName.append("hpcc_metrics_count_suffix"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are concerned about efficiency, then the following is better since it avoids cloning the strings:
const char * countSuffixMappingName = pIndexConfigTree->queryProp("@countSuffixMappingName");
if (!countSuffixMappingName)
countSuffixMappingName = "hpcc_metrics_count_suffix";
However this is only called once, so efficiency is not significant. Not something to change.
auto const &mappingName = it.first; | ||
auto kvPairs = it.second; | ||
auto const &matchValue = kvPairs["match"]; | ||
if (mappingName == countSuffixMappingName.str()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is confusing - because the RHS is a const char *, so this would intuitively be a pointer comparison. I think it probably is a string comparison - because the LHS is a std:string - but that isn't at all clear because of the use of auto.
I had thought this would mean each comparison is converting the const char * to a str::string, but the standard library does optimize that case.
Use strsame/streq would be clearer.
@@ -18,6 +18,22 @@ | |||
#include "jptree.hpp" | |||
#include "jstring.hpp" | |||
|
|||
//including cpp-httplib single header file REST client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better solution would be to move the definition of the ElasticMetricSink class into the c++ file. If this was included from many places, then each of those places would now be processing the entire header file.
@kenrowland there is an (unrelated) build error which needs addressing - probably by disabling a warning - before this can be merged. |
Added code to query configured index on ElasticSearch server for dynamic mapping template match values for hpcc metric type suffixes.
Signed-Off-By: Kenneth Rowland [email protected]
Type of change:
Checklist:
Smoketest:
Testing: