-
Notifications
You must be signed in to change notification settings - Fork 4
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
Issue #525: Add job duration metrics to connectors #528
Issue #525: Add job duration metrics to connectors #528
Conversation
MedMaalej
commented
Dec 27, 2024
* Compute job duration in validateConnectorDetectionCriteria * Remove monitorType('none') from surrounding strategy job duration metric * Add documentation for enableSelfMonitoring in configure-monitoring.md * Add unit tests
* Simplify strategy name matching code in hasExpectedJobTypes
I tested this ticket on the host Before the new developmentWe were not able to have job duration metrics in the connector monitors. The logs of metricshub reported that 53 monitors were discovered. After the new developmentWe are able to have job duration metrics in the connector monitors. The logs of metricshub also reported that 53 monitors were discovered ✔️ Non regression testThe other job duration metrics were not impacted and they still show up correctly. Grafana testThe monitor type connector is now displayed in the drop-down list values Surrounding strategy job duration metric testMetricshub logs display the job duration metric of the beforeAll and afterAll strategies without a monitor type
|
@MedMaalej , @NassimBtk : I suggest documenting the self-monitoring feature in a dedicated markdown file that will be placed under a Troubleshooting section (like we did for the hws doc: https://www.aws-dev.sentrysoftware.com/docs/hws-doc/latest/troubleshooting/self-monitoring.html). If you both agree, I will move forward and make the required changes. I can perform this task through #529 |
…ure/issue-525-Add-job-duration-metrics-to-connectors
Yes, I agree with you @iguitton showing |
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.
Review done.
case "simple": | ||
return monitorJob instanceof SimpleMonitorJob && ((SimpleMonitorJob) monitorJob).getSimple() != null; | ||
default: | ||
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.
return false; | |
throw new IllegalArgumentException("Unknown strategy job name: " + strategyJobName); |
.anyMatch(monitorJob -> { | ||
switch (strategyJobName.toLowerCase()) { | ||
case "discovery": | ||
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getDiscovery() != null; |
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.
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getDiscovery() != null; | |
return monitorJob instanceof StandardMonitorJob standardJob && standardJob.getDiscovery() != null; |
case "discovery": | ||
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getDiscovery() != null; | ||
case "collect": | ||
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getCollect() != null; |
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.
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getCollect() != null; | |
return monitorJob instanceof StandardMonitorJob standardJob && standardJob.getCollect() != null; |
case "collect": | ||
return monitorJob instanceof StandardMonitorJob && ((StandardMonitorJob) monitorJob).getCollect() != null; | ||
case "simple": | ||
return monitorJob instanceof SimpleMonitorJob && ((SimpleMonitorJob) monitorJob).getSimple() != null; |
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.
return monitorJob instanceof SimpleMonitorJob && ((SimpleMonitorJob) monitorJob).getSimple() != null; | |
return monitorJob instanceof SimpleMonitorJob simpleJob && simpleJob.getSimple() != null; |
collectJobDurationMetric(jobDurationMetricKey, startTime, endTime); | ||
} | ||
} | ||
|
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.
Reduce code duplicate using a supplier:
/**
* Sets the job duration metric in the host monitor with a monitor type.
*
* @param jobName the name of the job
* @param monitorType the monitor type in the job
* @param connectorId the ID of the connector
* @param jobStartTime the start time of the job in milliseconds
* @param jobEndTime the end time of the job in milliseconds
*/
protected void setJobDurationMetric(final String jobName, final String monitorType, final String connectorId, final long jobStartTime,
final long jobEndTime) {
setJobDurationMetric(() -> generateJobDurationMetricKey(jobName, monitorType, connectorId), jobStartTime, jobEndTime);
}
/**
* Sets the job duration metric in the host monitor with a monitor type.
*
* @param jobName the name of the job
* @param connectorId the ID of the connector
* @param jobStartTime the start time of the job in milliseconds
* @param jobEndTime the end time of the job in milliseconds
*/
protected void setJobDurationMetric(final String jobName, final String connectorId, final long jobStartTime,
final long jobEndTime) {
setJobDurationMetric(() -> generateJobDurationMetricKey(jobName, connectorId), jobStartTime, jobEndTime);
}
/**
* Sets the job duration metric in the host monitor with a monitor type.
*
* @param metricKeySupplier the supplier of the metric key
* @param startTime the start time of the job in milliseconds
* @param endTime the end time of the job in milliseconds
*/
private void setJobDurationMetric(
final Supplier<String> metricKeySupplier,
final long startTime,
final long endTime
) {
// If the enableSelfMonitoring flag is set to true, or it's not configured at all,
// set the job duration metric on the monitor. Otherwise, don't set it.
// By default, self monitoring is enabled
if (telemetryManager.getHostConfiguration().isEnableSelfMonitoring()) {
// Build the job duration metric key
final String jobDurationMetricKey = metricKeySupplier.get();
// Collect the job duration metric
collectJobDurationMetric(jobDurationMetricKey, startTime, endTime);
}
}
/**
* Generates the job duration metric key.
* @param jobName the name of the job
* @param monitorType the monitor type
* @param connectorId the ID of the connector
* @return the job duration metric key.
*/
private String generateJobDurationMetricKey(final String jobName, final String monitorType, final String connectorId) {
return new StringBuilder()
.append("metricshub.job.duration{job.type=\"")
.append(jobName)
.append("\", monitor.type=\"")
.append(monitorType)
.append("\", connector_id=\"")
.append(connectorId)
.append("\"}")
.toString();
}
/**
* Generate the job duration metric key.
* @param jobName the name of the job
* @param connectorId the ID of the
* @return the job duration metric key.
*/
private String generateJobDurationMetricKey(final String jobName, final String connectorId) {
return new StringBuilder()
.append("metricshub.job.duration{job.type=\"")
.append(jobName)
.append("\", connector_id=\"")
.append(connectorId)
.append("\"}")
.toString();
}
/**
* Collects and records the job duration metric.
*
* @param jobDurationMetricKey the key identifying the job duration metric
* @param startTime the start time of the job in milliseconds
* @param endTime the end time of the job in milliseconds
*/
private void collectJobDurationMetric(final String jobDurationMetricKey, final long startTime, final long endTime) {
final Monitor endpointHostMonitor = telemetryManager.getEndpointHostMonitor();
final MetricFactory metricFactory = new MetricFactory();
metricFactory.collectNumberMetric(
endpointHostMonitor,
jobDurationMetricKey,
(endTime - startTime) / 1000.0, // Job duration in seconds
strategyTime
);
}
* @param startTime the start time of the job in milliseconds | ||
* @param endTime the end time of the job in milliseconds | ||
*/ | ||
protected void setJobDurationMetricInHostMonitorWithoutMonitorType( |
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 method names (setJobDurationMetricInHostMonitorWithoutMonitorType
and setJobDurationMetricInHostMonitorWithMonitorType
) are overly verbose. setJobDurationMetric
is already sufficiently descriptive, especially when supplemented by clear Javadoc that explains the method's behavior.
* Refactor after code review
…s' of github.com:sentrysoftware/metricshub into feature/issue-525-Add-job-duration-metrics-to-connectors
Sounds like a good idea to me @NassimBtk and @MedMaalej |
@MedMaalej , @NassimBtk : this new feature will be documented through #533. Feel free to merge the PR when dev is ready. |
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.
Documentation will be performed through a different issue.