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

Remove unnecessary checks from MetricsHub extensions #270

Open
8 tasks
CherfaElyes opened this issue Jun 24, 2024 · 0 comments
Open
8 tasks

Remove unnecessary checks from MetricsHub extensions #270

CherfaElyes opened this issue Jun 24, 2024 · 0 comments
Assignees
Labels

Comments

@CherfaElyes
Copy link
Contributor

CherfaElyes commented Jun 24, 2024

Specification

Since the ExtensionManager is responsible of finding an extension that matches the configuration and the sources as follows:

public Optional<IProtocolExtension> findSourceExtension(
	final Source source,
	final TelemetryManager telemetryManager
	) {
	final List<IProtocolExtension> sourceExtensions = protocolExtensions
		.stream()
		.filter(extension ->
			telemetryManager
				.getHostConfiguration()
				.getConfigurations()
				.values()
				.stream()
				.anyMatch(extension::isValidConfiguration)
		)
		.filter(extension -> extension.getSupportedSources().contains(source.getClass()))
		.toList();

	return filterWithBusinessLogic(telemetryManager, sourceExtensions);
}

We are sure that within the extension, both the configuration and the source cannot be null. Consequently, there is no need to test if they are null within each extension.

Example - Check Source

The following check is not necessary within the WmiSourceProcessor since the call to this processor is only made after checking that Source instanceof WmiSource, which ensures that Source is not null.

if (wmiSource == null) {
	log.warn("Hostname {} - Malformed WMI source {}. Returning an empty table.", hostname, wmiSource);
	return SourceTable.empty();
}

Example - Check Configuration

This check is not relevant as we already know that the configuration cannot be null.

if (winConfiguration == null) {
	log.warn(
		"Hostname {} - The Windows protocol credentials are not configured. Cannot process Windows IPMI source.",
		telemetryManager.getHostname()
	);
	return SourceTable.empty();
}

This kind of checks needs to be removed from all the extensions and the source and criterion processors. Unit tests that fail after the refactoring need to be fixed as well.

Milestone

  • HTTP
  • IPMI
  • OsCommand
  • SNMP
  • SNMPv3
  • Wbem
  • WMI
  • WinRm
@CherfaElyes CherfaElyes self-assigned this Jun 24, 2024
@CherfaElyes CherfaElyes added java enhancement New feature or request labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants