diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionAutoCompleter.java index 7fc1da28e5..1a4927bf74 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionAutoCompleter.java @@ -1,5 +1,6 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import com.google.common.collect.ImmutableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import rocks.inspectit.ocelot.autocomplete.AutoCompleter; @@ -7,9 +8,10 @@ import rocks.inspectit.ocelot.config.validation.PropertyPathHelper; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.*; + /** * This AutoCompleter retrieves all actions which can be found in the present yaml-files. It is either triggered by * the path "inspectit.instrumentation.actions" or "inspectit.instrumentation.rules.*.*.*.action" @@ -17,17 +19,19 @@ @Component public class ActionAutoCompleter implements AutoCompleter { - private static List ACTION_DECLARATION_PATH = Arrays.asList("inspectit", "instrumentation", "actions"); + private static final List ACTION_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, ACTIONS); - private static List> ACTION_USAGE_PATHS = Arrays.asList( + private static final List> ACTION_USAGE_PATHS = ImmutableList.of( + // @formatter:off ACTION_DECLARATION_PATH, - Arrays.asList("inspectit", "instrumentation", "rules", "*", "preEntry", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "entry", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "exit", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "preEntry", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "postEntry", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "preExit", "*", "action"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "postExit", "*", "action") + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "preEntry", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "entry", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "exit", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "preEntry", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "postEntry", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "preExit", STAR, ACTION), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "postExit", STAR, ACTION) + // @formatter:on ); @Autowired @@ -41,13 +45,14 @@ public class ActionAutoCompleter implements AutoCompleter { * "inspectit.instrumentation.actions". '*' serves as a wild card here. * * @param path A given path as List. Each String should act as a literal of the path + * * @return A list of Strings resembling actions defined in the yaml files. */ @Override public List getSuggestions(List path) { ArrayList toReturn = new ArrayList<>(); - if (ACTION_USAGE_PATHS.stream(). - anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { + if (ACTION_USAGE_PATHS.stream() + .anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { toReturn.addAll(getActions()); } return toReturn; diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionInputAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionInputAutoCompleter.java index bccbbfb568..0a99ad2cd8 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionInputAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ActionInputAutoCompleter.java @@ -1,5 +1,6 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import com.google.common.collect.ImmutableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import rocks.inspectit.ocelot.autocomplete.AutoCompleter; @@ -7,11 +8,12 @@ import rocks.inspectit.ocelot.config.validation.PropertyPathHelper; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.*; + /** * This AutoCompleter retrieves all inputs for actions which can be found in the present yaml-files. It is triggered by * the path "inspectit.instrumentation.actions.*" @@ -25,33 +27,13 @@ public class ActionInputAutoCompleter implements AutoCompleter { private final static String ACTION_PLACEHOLDER = "ACTION_PLACEHOLDER"; - private final static List ACTION_OPTIONS = Arrays.asList( - "entry", - "exit", - "preEntry", - "postEntry", - "preExit", - "postExit" - ); - - private final static List INPUT_OPTIONS = Arrays.asList("data-input", "constant-input"); - - private final static List ACTION_INPUT_DECLARATION_PATH = Arrays.asList( - "inspectit", - "instrumentation", - "actions", - ACTION_PLACEHOLDER, - "input" - ); - - private final static List ACTION_INPUT_DEFAULT_USAGE_PATH = Arrays.asList( - "inspectit", - "instrumentation", - "rules", - "*", - SECTION_PLACEHOLDER, - "*", - INPUT_PLACEHOLDER); + private final static List ACTION_OPTIONS = ImmutableList.of("entry", "exit", "preEntry", "postEntry", "preExit", "postExit"); + + private final static List INPUT_OPTIONS = ImmutableList.of("data-input", "constant-input"); + + private final static List ACTION_INPUT_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, ACTIONS, ACTION_PLACEHOLDER, "input"); + + private final static List ACTION_INPUT_DEFAULT_USAGE_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, SECTION_PLACEHOLDER, STAR, INPUT_PLACEHOLDER); private static List> actionInputUsagePaths; @@ -87,12 +69,13 @@ private static void setupUsagePaths() { * Ignores action inputs that start with the String defined in INPUT_FILTER_ONSET. * * @param path A given path as List. Each String should act as a literal of the path. + * * @return A List of Strings resembling the declared actions that could be used with the given path. */ @Override public List getSuggestions(List path) { - if (actionInputUsagePaths.stream(). - anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { + if (actionInputUsagePaths.stream() + .anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { return getActionInputs(path); } return Collections.emptyList(); @@ -104,6 +87,7 @@ public List getSuggestions(List path) { * INPUT_FILTER_ONSET. * * @param path A given path as List. Each String should act as a literal of the path. + * * @return A List of Strings resembling the declared actions that could be used with the given path. */ private List getActionInputs(List path) { @@ -123,6 +107,7 @@ private List getActionInputs(List path) { * ["inspectit","instrumentation","actions","action_B","input"] is returned. * * @param path A given path as List. Each String should act as a literal of the path. + * * @return A List containing String Lists. Each of these Lists resemble one path as described. */ private List> buildActionPaths(List path) { @@ -142,6 +127,7 @@ private List> buildActionPaths(List path) { * found under "inspectit.instrumentation.rules.my-rule.entry.my-entry-method.action" are returned. * * @param path A List of Strings resembling a path to a rule-input. + * * @return The actions declared in this rule. */ private List getActions(List path) { diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/Constants.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/Constants.java new file mode 100644 index 0000000000..682bfd2c44 --- /dev/null +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/Constants.java @@ -0,0 +1,25 @@ +package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; + +/** + * Constants used by the auto-completer. + */ +interface Constants { + + String INSPECTIT = "inspectit"; + + String INSTRUMENTATION = "instrumentation"; + + String METRIC = "metric"; + + String METRICS = "metrics"; + + String ACTION = "action"; + + String RULES = "rules"; + + String SCOPES = "scopes"; + + String ACTIONS = "actions"; + + String STAR = "*"; +} diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/MetricsAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/MetricsAutoCompleter.java index d3c30e4c28..d89d778ebd 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/MetricsAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/MetricsAutoCompleter.java @@ -1,15 +1,17 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import com.google.common.collect.ImmutableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import rocks.inspectit.ocelot.autocomplete.AutoCompleter; import rocks.inspectit.ocelot.autocomplete.util.ConfigurationQueryHelper; import rocks.inspectit.ocelot.config.validation.PropertyPathHelper; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.*; + /** * Autocompleter which retrieves declared metric names. This autocompleter is triggered by the paths * "inspectit.instrumentation.rules.*.metrics", "inspectit.instrumentation.rules.*.metrics.*.metric" and @@ -24,15 +26,17 @@ public class MetricsAutoCompleter implements AutoCompleter { /** * The path under which metric names are defined. */ - private final static List METRICS_DECLARATION_PATH = Arrays.asList("inspectit", "metrics", "definitions"); + private final static List METRICS_DECLARATION_PATH = ImmutableList.of(INSPECTIT, METRICS, "definitions"); /** * All paths under which metric names are used. */ - private static final List> RULE_SUGGESTION_PATHS = Arrays.asList( + private static final List> RULE_SUGGESTION_PATHS = ImmutableList.of( + // @formatter:off METRICS_DECLARATION_PATH, - Arrays.asList("inspectit", "instrumentation", "rules", "*", "metrics"), - Arrays.asList("inspectit", "instrumentation", "rules", "*", "metrics", "*", "metric") + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, METRICS), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, METRICS, STAR, METRIC) + // @formatter:on ); /** @@ -40,9 +44,9 @@ public class MetricsAutoCompleter implements AutoCompleter { * all declared metrics that ca be used in this path as a List of Strings. * * @param path A given path as List. Each String should act as a literal of the path. + * * @return A List of Strings containing all declared metrics that could be used with the given path. */ - @Override public List getSuggestions(List path) { boolean matches = RULE_SUGGESTION_PATHS.stream() diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java index 5850b3597a..56e17bce66 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java @@ -1,5 +1,7 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.INSPECTIT; + import com.google.common.annotations.VisibleForTesting; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; @@ -22,8 +24,8 @@ public class ModelAutoCompleter implements AutoCompleter { @Override public List getSuggestions(List path) { if (CollectionUtils.isEmpty(path) || (path.size() == 1 && path.get(0).equals(""))) { - return Collections.singletonList("inspectit"); - } else if (!path.isEmpty() && !path.get(0).equals("inspectit")) { + return Collections.singletonList(INSPECTIT); + } else if (!path.isEmpty() && !path.get(0).equals(INSPECTIT)) { return Collections.emptyList(); } return collectProperties(path.subList(1, path.size())); diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/RuleAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/RuleAutoCompleter.java index 8e7d1f47a3..67d0ae8d37 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/RuleAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/RuleAutoCompleter.java @@ -1,15 +1,17 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import com.google.common.collect.ImmutableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import rocks.inspectit.ocelot.autocomplete.AutoCompleter; import rocks.inspectit.ocelot.autocomplete.util.ConfigurationQueryHelper; import rocks.inspectit.ocelot.config.validation.PropertyPathHelper; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.*; + /** * This AutoCompleter retrieves all rules which can be found in the present yaml-files. It is triggered by * the path "inspectit.instrumentation.rules". @@ -23,14 +25,16 @@ public class RuleAutoCompleter implements AutoCompleter { /** * The path under which rule names are defined. */ - private static final List RULE_DEFINITION_PATH = Arrays.asList("inspectit", "instrumentation", "rules"); + private static final List RULE_DEFINITION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES); /** * All paths under which rule names are used. */ - private static final List> RULE_SUGGESTION_PATHS = Arrays.asList( + private static final List> RULE_SUGGESTION_PATHS = ImmutableList.of( + // @formatter:off RULE_DEFINITION_PATH, - Arrays.asList("inspectit", "instrumentation", "rules", "*", "include") + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, "include") + // @formatter:on ); /** @@ -38,6 +42,7 @@ public class RuleAutoCompleter implements AutoCompleter { * all declared rules that could be used in this path as List of Strings. * * @param path A given path as List. Each String should act as a literal of the path. + * * @return A List of Strings containing all declared rules that could be used with the given path. */ diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ScopeAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ScopeAutoCompleter.java index 1a9c2028f6..f40fa4611d 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ScopeAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ScopeAutoCompleter.java @@ -1,5 +1,6 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; +import com.google.common.collect.ImmutableList; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -7,10 +8,11 @@ import rocks.inspectit.ocelot.autocomplete.util.ConfigurationQueryHelper; import rocks.inspectit.ocelot.config.validation.PropertyPathHelper; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.*; + /** * This AutoCompleter retrieves all scopes which can be found in the present yaml-files. It is either triggered by * the path "inspectit.instrumentation.scopes" or "inspectit.instrumentation.rules.*.scopes" @@ -19,12 +21,14 @@ @Component public class ScopeAutoCompleter implements AutoCompleter { - private final static List SCOPE_DECLARATION_PATH = Arrays.asList("inspectit", "instrumentation", "scopes"); + private final static List SCOPE_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, SCOPES); - private final static List> SCOPE_USAGE_PATHS = Arrays.asList( + private final static List> SCOPE_USAGE_PATHS = ImmutableList.of( + // @formatter:off SCOPE_DECLARATION_PATH, - Arrays.asList("inspectit", "instrumentation", "rules", "*", "scopes"), - Arrays.asList("inspectit", "instrumentation", "scopes", "*", "exclude") + ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, SCOPES), + ImmutableList.of(INSPECTIT, INSTRUMENTATION, SCOPES, STAR, "exclude") + // @formatter:on ); @Autowired @@ -32,8 +36,8 @@ public class ScopeAutoCompleter implements AutoCompleter { @Override public List getSuggestions(List path) { - if (SCOPE_USAGE_PATHS.stream(). - anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { + if (SCOPE_USAGE_PATHS.stream() + .anyMatch(actionUsagePath -> PropertyPathHelper.comparePaths(path, actionUsagePath))) { return getScopes(); } return Collections.emptyList(); diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/accessor/git/RevisionAccess.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/accessor/git/RevisionAccess.java index 05e5491f10..51b10fc06c 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/accessor/git/RevisionAccess.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/accessor/git/RevisionAccess.java @@ -186,7 +186,7 @@ protected String verifyPath(String relativeBasePath, String relativePath) throws Path path = Paths.get(relativePath).normalize(); if (StringUtils.isBlank(relativeBasePath)) { - return path.toString().replaceAll("\\\\", "/"); + return path.toString().replace("\\\\", "/"); } Path basePath = Paths.get(relativeBasePath).normalize(); @@ -196,7 +196,7 @@ protected String verifyPath(String relativeBasePath, String relativePath) throws throw new IllegalArgumentException("User path escapes the base path: " + relativePath); } - return resolvedPath.toString().replaceAll("\\\\", "/"); + return resolvedPath.toString().replace("\\\\", "/"); } @Override diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/versioning/VersioningManager.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/versioning/VersioningManager.java index ae2227e09e..50a2f80ad3 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/versioning/VersioningManager.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/file/versioning/VersioningManager.java @@ -49,6 +49,11 @@ @Slf4j public class VersioningManager { + /** + * Exception message in case a expected parent does not exist. + */ + private static final String EXPECTED_PARENT_EXIST = "Expected parent to exist"; + /** * The tag name used for marking which commit has been used for the last remote sync. */ @@ -510,7 +515,7 @@ private Collection findModifyingAuthors(String file, RevCommit baseCommi break; //THe file has been added, no need to take previous changes into account } newRevision = newRevision.getPreviousRevision() - .orElseThrow(() -> new IllegalStateException("Expected parent to exist")); + .orElseThrow(() -> new IllegalStateException(EXPECTED_PARENT_EXIST)); if (newRevision.configurationFileExists(file) && newRevision.readConfigurationFile(file) .get() .equals(baseContent)) { @@ -538,7 +543,7 @@ private Collection findAuthorsSinceAddition(String file, RevCommit newCo authors.add(newRevision.getAuthorName()); } newRevision = newRevision.getPreviousRevision() - .orElseThrow(() -> new IllegalStateException("Expected parent to exist")); + .orElseThrow(() -> new IllegalStateException(EXPECTED_PARENT_EXIST)); } authors.add(newRevision.getAuthorName()); //Also add the name of the person who added the file return authors; @@ -571,7 +576,7 @@ private String findDeletingAuthor(String file, RevCommit baseCommit, RevCommit n } previous = newRevision; newRevision = newRevision.getPreviousRevision() - .orElseThrow(() -> new IllegalStateException("Expected parent to exist")); + .orElseThrow(() -> new IllegalStateException(EXPECTED_PARENT_EXIST)); } return previous.getAuthorName(); //in case an amend happened, this will be the correct user } @@ -590,7 +595,7 @@ private String findDeletingAuthor(String file, RevCommit baseCommit, RevCommit n private RevisionAccess findLastChangingRevision(String file, RevisionAccess baseRevision) { while (!baseRevision.isConfigurationFileAdded(file) && !baseRevision.isConfigurationFileModified(file)) { baseRevision = baseRevision.getPreviousRevision() - .orElseThrow(() -> new IllegalStateException("Expected parent to exist")); + .orElseThrow(() -> new IllegalStateException(EXPECTED_PARENT_EXIST)); } return baseRevision; } diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/KapacitorTaskController.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/KapacitorTaskController.java index 164a5543ba..806b7a03fe 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/KapacitorTaskController.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/KapacitorTaskController.java @@ -18,15 +18,35 @@ @RestController public class KapacitorTaskController extends KapacitorBaseController { + /** + * URL path of Kapacitor's task endpoint. + */ + private static final String KAPACITOR_PATH_TASKS = "/kapacitor/v1/tasks"; + + /** + * URL path of Kapacitor's task endpoint for referencing a specific task by its ID. + */ + private static final String KAPACITOR_PATH_TASKS_ID = "/kapacitor/v1/tasks/{taskId}"; + + /** + * URL path used by the configuration server for providing task management. + */ + private static final String ALERT_PATH_TASKS = "/alert/kapacitor/tasks"; + + /** + * URL path used by the configuration server for providing task management of a specific task. + */ + private static final String ALERT_PATH_TASKS_ID = "/alert/kapacitor/tasks/{taskId}"; + @Autowired public KapacitorTaskController(InspectitServerSettings settings) { super(settings); } @ApiOperation(value = "Provides a list with basic information about each kapacitor task. Only tasks based on templates will be listed.") - @GetMapping("/alert/kapacitor/tasks") + @GetMapping(ALERT_PATH_TASKS) public List getAllTasks() { - ObjectNode response = kapacitor().getForEntity("/kapacitor/v1/tasks", ObjectNode.class).getBody(); + ObjectNode response = kapacitor().getForEntity(KAPACITOR_PATH_TASKS, ObjectNode.class).getBody(); if (response == null) { return Collections.emptyList(); @@ -39,19 +59,18 @@ public List getAllTasks() { @ApiOperation(value = "Provides detailed information about a given kapacitor task") - @GetMapping("/alert/kapacitor/tasks/{taskId}") + @GetMapping(ALERT_PATH_TASKS_ID) public Task getTask(@PathVariable @ApiParam("The id of the task to query") String taskId) { - ObjectNode response = kapacitor().getForEntity("/kapacitor/v1/tasks/{taskId}", ObjectNode.class, taskId) - .getBody(); + ObjectNode response = kapacitor().getForEntity(KAPACITOR_PATH_TASKS_ID, ObjectNode.class, taskId).getBody(); return Task.fromKapacitorResponse(response); } @Secured(UserRoleConfiguration.WRITE_ACCESS_ROLE) @ApiOperation(value = "Inserts a new Kapacitor task") - @PostMapping("/alert/kapacitor/tasks") + @PostMapping(ALERT_PATH_TASKS) public Task addTask(@RequestBody Task task) { - ObjectNode response = kapacitor().postForEntity("/kapacitor/v1/tasks", task.toKapacitorRequest(), ObjectNode.class) + ObjectNode response = kapacitor().postForEntity(KAPACITOR_PATH_TASKS, task.toKapacitorRequest(), ObjectNode.class) .getBody(); return Task.fromKapacitorResponse(response); @@ -59,9 +78,9 @@ public Task addTask(@RequestBody Task task) { @Secured(UserRoleConfiguration.WRITE_ACCESS_ROLE) @ApiOperation(value = "Updates one or more settings of a kapacitor task") - @PatchMapping("/alert/kapacitor/tasks/{taskId}") + @PatchMapping(ALERT_PATH_TASKS_ID) public Task updateTask(@PathVariable @ApiParam("The id of the task to update") String taskId, @RequestBody Task task) { - ObjectNode response = kapacitor().patchForObject("/kapacitor/v1/tasks/{taskId}", task.toKapacitorRequest(), ObjectNode.class, taskId); + ObjectNode response = kapacitor().patchForObject(KAPACITOR_PATH_TASKS_ID, task.toKapacitorRequest(), ObjectNode.class, taskId); triggerTaskReload(task); return Task.fromKapacitorResponse(response); @@ -69,9 +88,9 @@ public Task updateTask(@PathVariable @ApiParam("The id of the task to update") S @Secured(UserRoleConfiguration.WRITE_ACCESS_ROLE) @ApiOperation(value = "Removes a task") - @DeleteMapping("/alert/kapacitor/tasks/{taskId}") + @DeleteMapping(ALERT_PATH_TASKS_ID) public void removeTask(@PathVariable @ApiParam("The id of the task to delete") String taskId) { - kapacitorRestTemplate.delete("/kapacitor/v1/tasks/{taskId}", taskId); + kapacitorRestTemplate.delete(KAPACITOR_PATH_TASKS_ID, taskId); } /** diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/model/Task.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/model/Task.java index 3b9c23b90d..ba6c5c950d 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/model/Task.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/alert/kapacitor/model/Task.java @@ -25,8 +25,17 @@ @NoArgsConstructor public class Task { + private static final String VALUE = "value"; + + private static final String STRING = "string"; + + private static final String TEMPLATE_ID = "template-id"; + private static final ObjectMapper mapper = new ObjectMapper(); + /** + * The task's id. + */ String id; /** @@ -75,10 +84,10 @@ public ObjectNode toKapacitorRequest() { result.put("status", status); } if (template != null) { - result.put("template-id", template); + result.put(TEMPLATE_ID, template); TemplateVariable.builder() .name(TemplateVariable.TEMPLATE_REFERENCE_VARIABLE) - .type("string") + .type(STRING) .value(template) .build() .insertIntoKapacitorVars(mapper, varsNode); @@ -86,7 +95,7 @@ public ObjectNode toKapacitorRequest() { if (topic != null) { TemplateVariable.builder() .name(TemplateVariable.TOPIC_VARIABLE) - .type("string") + .type(STRING) .value(topic) .build() .insertIntoKapacitorVars(mapper, varsNode); @@ -94,7 +103,7 @@ public ObjectNode toKapacitorRequest() { if (description != null) { TemplateVariable.builder() .name(TemplateVariable.TEMPLATE_DESCRIPTION_VARIABLE) - .type("string") + .type(STRING) .value(description) .build() .insertIntoKapacitorVars(mapper, varsNode); @@ -132,9 +141,9 @@ public static Task fromKapacitorResponse(JsonNode task) { if (task.has("vars")) { decodeVariables(task.path("vars"), builder); } - if (task.has("template-id")) { + if (task.has(TEMPLATE_ID)) { //override the template setting from the dummy variable with teh actual value if available - builder.template(task.get("template-id").asText()); + builder.template(task.get(TEMPLATE_ID).asText()); } return builder.build(); } @@ -151,11 +160,11 @@ private static void decodeVariables(JsonNode variables, Task.TaskBuilder builder String name = nameIterator.next(); JsonNode var = variables.path(name); if (TemplateVariable.TEMPLATE_DESCRIPTION_VARIABLE.equals(name)) { - builder.description(var.path("value").asText()); + builder.description(var.path(VALUE).asText()); } else if (TemplateVariable.TOPIC_VARIABLE.equals(name)) { - builder.topic(var.path("value").asText()); + builder.topic(var.path(VALUE).asText()); } else if (TemplateVariable.TEMPLATE_REFERENCE_VARIABLE.equals(name)) { - builder.template(var.path("value").asText()); + builder.template(var.path(VALUE).asText()); } else { resultVars.add(TemplateVariable.fromKapacitorResponse(name, var)); } diff --git a/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/AppStartupRunner.java b/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/AppStartupRunner.java index 1656fc0210..c8f17a86b4 100644 --- a/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/AppStartupRunner.java +++ b/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/AppStartupRunner.java @@ -14,7 +14,12 @@ public class AppStartupRunner implements ApplicationRunner { /** - * The file used to load the servers's version. + * Version string of unknown versions. + */ + private static final String UNKNOWN = "UNKNOWN"; + + /** + * The file used to load the server's version. */ private static final String SERVER_VERSION_INFORMATION_FILE = "/eum-version.info"; @@ -54,9 +59,9 @@ private void readVersionInformation() { bommerangjsVersion = reader.readLine(); } catch (Exception e) { log.warn("Could not read server version information file."); - serverVersion = "UNKNOWN"; - serverBuildDate = "UNKNOWN"; - bommerangjsVersion = "UNKNOWN"; + serverVersion = UNKNOWN; + serverBuildDate = UNKNOWN; + bommerangjsVersion = UNKNOWN; } } } \ No newline at end of file diff --git a/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/CountryCodeBeaconProcessor.java b/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/CountryCodeBeaconProcessor.java index ad51567941..26d03709da 100644 --- a/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/CountryCodeBeaconProcessor.java +++ b/components/inspectit-ocelot-eum-server/src/main/java/rocks/inspectit/oce/eum/server/beacon/processor/CountryCodeBeaconProcessor.java @@ -19,7 +19,7 @@ @Component public class CountryCodeBeaconProcessor implements BeaconProcessor { - public static String TAG_COUNTRY_CODE = "COUNTRY_CODE"; + public static final String TAG_COUNTRY_CODE = "COUNTRY_CODE"; @Autowired private IPUtils ipUtils; diff --git a/inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/instrumentation/noop/NoopMethodHook.java b/inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/instrumentation/noop/NoopMethodHook.java index b9ce0f6fd3..e27f8d1367 100644 --- a/inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/instrumentation/noop/NoopMethodHook.java +++ b/inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/instrumentation/noop/NoopMethodHook.java @@ -6,7 +6,7 @@ public class NoopMethodHook implements IMethodHook { - public static NoopMethodHook INSTANCE = new NoopMethodHook(); + public static final NoopMethodHook INSTANCE = new NoopMethodHook(); private NoopMethodHook() { } diff --git a/inspectit-ocelot-config/src/main/java/rocks/inspectit/ocelot/config/model/instrumentation/actions/ActionCallSettings.java b/inspectit-ocelot-config/src/main/java/rocks/inspectit/ocelot/config/model/instrumentation/actions/ActionCallSettings.java index 1cad120129..5c7146a023 100644 --- a/inspectit-ocelot-config/src/main/java/rocks/inspectit/ocelot/config/model/instrumentation/actions/ActionCallSettings.java +++ b/inspectit-ocelot-config/src/main/java/rocks/inspectit/ocelot/config/model/instrumentation/actions/ActionCallSettings.java @@ -24,6 +24,12 @@ @EqualsAndHashCode(callSuper = true) public class ActionCallSettings extends ConditionalActionSettings { + private static final String PARAMETER_ACTION = "action"; + + private static final String PARAMETER_VAR = "var"; + + private static final String PARAMETER_TYPE = "type"; + /** * The name of the action. * References the defined actions in {@link InstrumentationSettings#getActions()}. @@ -60,7 +66,7 @@ public void performValidation(InstrumentationSettings container, ViolationBuilde val actionConf = container.getActions().get(action); if (actionConf == null) { vios.message("Action with name '{action}' does not exist!") - .parameter("action", action) + .parameter(PARAMETER_ACTION, action) .buildAndPublish(); } else { checkAllInputsAssigned(actionConf, vios); @@ -76,40 +82,38 @@ private void checkNoDuplicateAssignments(ViolationBuilder vios) { .distinct() .filter(constantInput::containsKey) .filter(dataInput::containsKey) - .forEach(varName -> vios - .message("Multiple assignments are given to same variable '{var}'!") - .parameter("var", varName) + .forEach(varName -> vios.message("Multiple assignments are given to same variable '{var}'!") + .parameter(PARAMETER_VAR, varName) .buildAndPublish()); } private void checkAllInputsAssigned(GenericActionSettings actionConf, ViolationBuilder vios) { - actionConf.getInput().keySet().stream() + actionConf.getInput() + .keySet() + .stream() .filter(varName -> !GenericActionSettings.isSpecialVariable(varName)) .filter(varName -> !constantInput.containsKey(varName)) .filter(varName -> !dataInput.containsKey(varName)) - .forEach(varName -> vios - .message("Parameter '{var}' of action '{action}' is not assigned!") - .parameter("var", varName) - .parameter("action", action) + .forEach(varName -> vios.message("Parameter '{var}' of action '{action}' is not assigned!") + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) .buildAndPublish()); } private void checkNoSpecialInputsAssigned(ViolationBuilder vios) { Stream.concat(constantInput.keySet().stream(), dataInput.keySet().stream()) .filter(GenericActionSettings::isSpecialVariable) - .forEach(varName -> vios - .message("Assigned parameter '{var}' is a special variable and must not be assigned manually!") - .parameter("var", varName) + .forEach(varName -> vios.message("Assigned parameter '{var}' is a special variable and must not be assigned manually!") + .parameter(PARAMETER_VAR, varName) .buildAndPublish()); } private void checkNoNonExistingInputsAssigned(GenericActionSettings actionConf, ViolationBuilder vios) { Stream.concat(constantInput.keySet().stream(), dataInput.keySet().stream()) .filter(varName -> !actionConf.getInput().containsKey(varName)) - .forEach(varName -> vios - .message("Assigned parameter '{var}' does not exist as input for action '{action}'!") - .parameter("var", varName) - .parameter("action", action) + .forEach(varName -> vios.message("Assigned parameter '{var}' does not exist as input for action '{action}'!") + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) .buildAndPublish()); } @@ -120,9 +124,9 @@ private void checkConstantInputsCanBeDecoded(GenericActionSettings actionConf, V if (value == null) { if (AutoboxingHelper.isPrimitiveType(type)) { vios.message("The input '{var}' of '{action}' cannot be 'null' as it is a primitive ('{type}')!") - .parameter("var", varName) - .parameter("action", action) - .parameter("type", type) + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) + .parameter(PARAMETER_TYPE, type) .buildAndPublish(); } } else { @@ -138,9 +142,9 @@ private void checkConstantAssignmentForNonNullValue(GenericActionSettings action typeClass = AutoboxingHelper.getWrapperClass(type); if (value instanceof String && ((String) value).isEmpty()) { vios.message("The input '{var}' of '{action}' cannot be empty as it is a primitive or wrapper type ('{type}')!") - .parameter("var", varName) - .parameter("action", action) - .parameter("type", type) + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) + .parameter(PARAMETER_TYPE, type) .buildAndPublish(); } } else { @@ -148,9 +152,9 @@ private void checkConstantAssignmentForNonNullValue(GenericActionSettings action } if (typeClass == null) { vios.message("The input '{var}' of '{action}' cannot be specified as a non-null constant value, as it has the unknown type '{type}'!") - .parameter("var", varName) - .parameter("action", action) - .parameter("type", type) + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) + .parameter(PARAMETER_TYPE, type) .buildAndPublish(); } else { try { @@ -158,9 +162,9 @@ private void checkConstantAssignmentForNonNullValue(GenericActionSettings action } catch (Exception e) { vios.message("The given value '{value}' for input '{var}' of '{action}' cannot be converted to '{type}': {errorMsg}") .parameter("value", value) - .parameter("var", varName) - .parameter("action", action) - .parameter("type", type) + .parameter(PARAMETER_VAR, varName) + .parameter(PARAMETER_ACTION, action) + .parameter(PARAMETER_TYPE, type) .parameter("errorMsg", e.getMessage()) .buildAndPublish(); } diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/AgentImpl.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/AgentImpl.java index e3af0a5e28..3aac4a8538 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/AgentImpl.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/AgentImpl.java @@ -63,7 +63,7 @@ public class AgentImpl implements IAgent { public void start(String cmdArgs, Instrumentation instrumentation) { ClassLoader classloader = AgentImpl.class.getClassLoader(); - LOGGER.info("Starting inspectIT Ocelot Agent...", getVersion()); + LOGGER.info("Starting inspectIT Ocelot Agent..."); LOGGER.info("\tVersion: {}", getVersion()); LOGGER.info("\tBuild Date: {}", getBuildDate()); logOpenCensusClassLoader(); diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/actions/GenericActionGenerator.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/actions/GenericActionGenerator.java index 184849b0e4..f1be404040 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/actions/GenericActionGenerator.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/actions/GenericActionGenerator.java @@ -60,16 +60,16 @@ public class GenericActionGenerator { * Guava seems to not allow null keys. * Therefore we just use this object as replacement for the bootstrap loader. */ - private static ClassLoader BOOTSTRAP_LOADER_MARKER = new URLClassLoader(new URL[]{}); + private static final ClassLoader BOOTSTRAP_LOADER_MARKER = new URLClassLoader(new URL[]{}); - private static String NON_VOID_GENERIC_ACTION_STRUCTURAL_ID = "genericAction"; - private static String VOID_GENERIC_ACTION_STRUCTURAL_ID = "voidGenericAction"; + private static final String NON_VOID_GENERIC_ACTION_STRUCTURAL_ID = "genericAction"; + private static final String VOID_GENERIC_ACTION_STRUCTURAL_ID = "voidGenericAction"; - private static String METHOD_ARGS = "$1"; - private static String THIZ = "$2"; - private static String RETURN_VALUE = "$3"; - private static String THROWN = "$4"; - private static String ADDITIONAL_ARGS = "$5"; + private static final String METHOD_ARGS = "$1"; + private static final String THIZ = "$2"; + private static final String RETURN_VALUE = "$3"; + private static final String THROWN = "$4"; + private static final String ADDITIONAL_ARGS = "$5"; @Autowired private ClassInjector classInjector; diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/special/ScheduledExecutorContextPropagationSensor.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/special/ScheduledExecutorContextPropagationSensor.java index f4315e127b..1bcb63eb17 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/special/ScheduledExecutorContextPropagationSensor.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/special/ScheduledExecutorContextPropagationSensor.java @@ -49,6 +49,11 @@ @Component public class ScheduledExecutorContextPropagationSensor implements SpecialSensor { + /** + * Identifier for lambda classes. + */ + private static final String LAMBDA = "$$Lambda$"; + private static final ElementMatcher CLASSES_MATCHER = isSubTypeOf(ScheduledExecutorService.class); @Override @@ -81,7 +86,7 @@ private static class ScheduledExecutorRunnableAdvice { @Advice.OnMethodEnter public static void onMethodEnter(@Advice.Argument(value = 0, readOnly = false) Runnable runnable) { if (Instances.contextManager.enterCorrelation()) { - if (runnable.getClass().getName().contains("$$Lambda$")) { + if (runnable.getClass().getName().contains(LAMBDA)) { // order is important because the log-correlator requires the restored context, thus, have to be // called after the context wrapper (needs to be nested by it) runnable = Instances.logTraceCorrelator.wrap(runnable); @@ -110,7 +115,7 @@ private static class ScheduledExecutorRunnableContinuousAdvice { @Advice.OnMethodEnter public static void onMethodEnter(@Advice.Argument(value = 0, readOnly = false) Runnable runnable) { if (Instances.contextManager.enterCorrelation()) { - if (runnable.getClass().getName().contains("$$Lambda$")) { + if (runnable.getClass().getName().contains(LAMBDA)) { // order is important because the log-correlator requires the restored context, thus, have to be // called after the context wrapper (needs to be nested by it) runnable = Instances.logTraceCorrelator.wrap(runnable); @@ -138,7 +143,7 @@ private static class ScheduledExecutorCallableAdvice { @Advice.OnMethodEnter public static void onMethodEnter(@Advice.Argument(value = 0, readOnly = false) Callable callable) { if (Instances.contextManager.enterCorrelation()) { - if (callable.getClass().getName().contains("$$Lambda$")) { + if (callable.getClass().getName().contains(LAMBDA)) { // order is important because the log-correlator requires the restored context, thus, have to be // called after the context wrapper (needs to be nested by it) callable = Instances.logTraceCorrelator.wrap(callable); diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/GCMetricsRecorder.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/GCMetricsRecorder.java index 7e66423b51..8a163dcacd 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/GCMetricsRecorder.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/GCMetricsRecorder.java @@ -39,7 +39,7 @@ public class GCMetricsRecorder extends AbstractMetricsRecorder { private static final String PAUSE_METRIC_NAME = "pause"; - private static final String PAUSE_METRIC_FULL_NAME = METRIC_NAME_PREFIX + "pause"; + private static final String PAUSE_METRIC_FULL_NAME = METRIC_NAME_PREFIX + PAUSE_METRIC_NAME; private static final String MEMORY_PROMOTED_METRIC_NAME = "memory.promoted"; diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/ProcessorMetricsRecorder.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/ProcessorMetricsRecorder.java index 00f0d7af4f..612776bf24 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/ProcessorMetricsRecorder.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/metrics/system/ProcessorMetricsRecorder.java @@ -32,6 +32,8 @@ public class ProcessorMetricsRecorder extends AbstractPollingMetricsRecorder { private static final String PROCESS_USAGE_METRIC_FULL_NAME = "process/cpu/usage"; + private static final String METRIC_UNAVAILABLE = "Metric '{}' will not be recorded because '{}' is unavailable."; + private static final List OPERATING_SYSTEM_BEAN_CLASS_NAMES = Arrays.asList( "com.sun.management.OperatingSystemMXBean", // HotSpot "com.ibm.lang.management.OperatingSystemMXBean" // J9 @@ -54,20 +56,22 @@ public ProcessorMetricsRecorder() { @Override protected void init() { super.init(); + final String METH_SYS_CPU_LOAD = "getSystemCpuLoad"; + final String METH_PROC_CPU_LOAD = "getProcessCpuLoad"; runtime = Runtime.getRuntime(); operatingSystemBean = ManagementFactory.getOperatingSystemMXBean(); - systemCpuUsage = findOSBeanMethod("getSystemCpuLoad"); - processCpuUsage = findOSBeanMethod("getProcessCpuLoad"); + systemCpuUsage = findOSBeanMethod(METH_SYS_CPU_LOAD); + processCpuUsage = findOSBeanMethod(METH_PROC_CPU_LOAD); //returns negative values if unavailable averageLoadAvailable = operatingSystemBean.getSystemLoadAverage() >= 0; if (!systemCpuUsage.isPresent()) { - log.info("Unable to locate 'getSystemCpuLoad' on operation system bean. Metric " + SYSTEM_USAGE_METRIC_FULL_NAME + " is unavailable."); + log.info(METRIC_UNAVAILABLE, SYSTEM_USAGE_METRIC_FULL_NAME, METH_SYS_CPU_LOAD); } if (!systemCpuUsage.isPresent()) { - log.info("Unable to locate 'getProcessCpuLoad' on operation system bean. Metric " + PROCESS_USAGE_METRIC_FULL_NAME + " is unavailable."); + log.info(METRIC_UNAVAILABLE, PROCESS_USAGE_METRIC_FULL_NAME, METH_PROC_CPU_LOAD); } if (!averageLoadAvailable) { - log.info("'getAverageLoad()' is not available on this system. Metric " + AVERAGE_LOAD_METRIC_FULL_NAME + " is unavailable."); + log.info(METRIC_UNAVAILABLE, AVERAGE_LOAD_METRIC_FULL_NAME, "getAverageLoad"); } }