Skip to content

Commit

Permalink
Closes #1173 - Fix String related issues (#1174)
Browse files Browse the repository at this point in the history
Co-authored-by: Marius Oehler <[email protected]>
  • Loading branch information
boris-unckel and mariusoe authored Sep 30, 2021
1 parent 3b7216d commit 70b1ea4
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
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.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"
*/
@Component
public class ActionAutoCompleter implements AutoCompleter {

private static List<String> ACTION_DECLARATION_PATH = Arrays.asList("inspectit", "instrumentation", "actions");
private static final List<String> ACTION_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, ACTIONS);

private static List<List<String>> ACTION_USAGE_PATHS = Arrays.asList(
private static final List<List<String>> 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
Expand All @@ -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<String> getSuggestions(List<String> path) {
ArrayList<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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.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.*"
Expand All @@ -25,33 +27,13 @@ public class ActionInputAutoCompleter implements AutoCompleter {

private final static String ACTION_PLACEHOLDER = "ACTION_PLACEHOLDER";

private final static List<String> ACTION_OPTIONS = Arrays.asList(
"entry",
"exit",
"preEntry",
"postEntry",
"preExit",
"postExit"
);

private final static List<String> INPUT_OPTIONS = Arrays.asList("data-input", "constant-input");

private final static List<String> ACTION_INPUT_DECLARATION_PATH = Arrays.asList(
"inspectit",
"instrumentation",
"actions",
ACTION_PLACEHOLDER,
"input"
);

private final static List<String> ACTION_INPUT_DEFAULT_USAGE_PATH = Arrays.asList(
"inspectit",
"instrumentation",
"rules",
"*",
SECTION_PLACEHOLDER,
"*",
INPUT_PLACEHOLDER);
private final static List<String> ACTION_OPTIONS = ImmutableList.of("entry", "exit", "preEntry", "postEntry", "preExit", "postExit");

private final static List<String> INPUT_OPTIONS = ImmutableList.of("data-input", "constant-input");

private final static List<String> ACTION_INPUT_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, ACTIONS, ACTION_PLACEHOLDER, "input");

private final static List<String> ACTION_INPUT_DEFAULT_USAGE_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES, STAR, SECTION_PLACEHOLDER, STAR, INPUT_PLACEHOLDER);

private static List<List<String>> actionInputUsagePaths;

Expand Down Expand Up @@ -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<String> getSuggestions(List<String> 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();
Expand All @@ -104,6 +87,7 @@ public List<String> getSuggestions(List<String> 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<String> getActionInputs(List<String> path) {
Expand All @@ -123,6 +107,7 @@ private List<String> getActionInputs(List<String> 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<List<String>> buildActionPaths(List<String> path) {
Expand All @@ -142,6 +127,7 @@ private List<List<String>> buildActionPaths(List<String> 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<String> getActions(List<String> path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "*";
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,25 +26,27 @@ public class MetricsAutoCompleter implements AutoCompleter {
/**
* The path under which metric names are defined.
*/
private final static List<String> METRICS_DECLARATION_PATH = Arrays.asList("inspectit", "metrics", "definitions");
private final static List<String> METRICS_DECLARATION_PATH = ImmutableList.of(INSPECTIT, METRICS, "definitions");

/**
* All paths under which metric names are used.
*/
private static final List<List<String>> RULE_SUGGESTION_PATHS = Arrays.asList(
private static final List<List<String>> 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
);

/**
* Checks if the given path leads to a metric Attribute, e.g. "inspectit.instrumentation.rules.*.metrics" and returns
* 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<String> getSuggestions(List<String> path) {
boolean matches = RULE_SUGGESTION_PATHS.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,8 +24,8 @@ public class ModelAutoCompleter implements AutoCompleter {
@Override
public List<String> getSuggestions(List<String> 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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".
Expand All @@ -23,21 +25,24 @@ public class RuleAutoCompleter implements AutoCompleter {
/**
* The path under which rule names are defined.
*/
private static final List<String> RULE_DEFINITION_PATH = Arrays.asList("inspectit", "instrumentation", "rules");
private static final List<String> RULE_DEFINITION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, RULES);

/**
* All paths under which rule names are used.
*/
private static final List<List<String>> RULE_SUGGESTION_PATHS = Arrays.asList(
private static final List<List<String>> 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
);

/**
* Checks if the given path leads to a rule Attribute, e.g. "inspectit.instrumentation.rules" and returns
* 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.
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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;
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 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"
Expand All @@ -19,21 +21,23 @@
@Component
public class ScopeAutoCompleter implements AutoCompleter {

private final static List<String> SCOPE_DECLARATION_PATH = Arrays.asList("inspectit", "instrumentation", "scopes");
private final static List<String> SCOPE_DECLARATION_PATH = ImmutableList.of(INSPECTIT, INSTRUMENTATION, SCOPES);

private final static List<List<String>> SCOPE_USAGE_PATHS = Arrays.asList(
private final static List<List<String>> 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
private ConfigurationQueryHelper configurationQueryHelper;

@Override
public List<String> getSuggestions(List<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Loading

0 comments on commit 70b1ea4

Please sign in to comment.