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

SWATCH-1801: Use simple solution to replace SPeL expression parser #2611

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Oct 5, 2023

Jira issue: SWATCH-1801

Description

This is the simplest solution I can think of, to replace the SPeL expression parser which perfectly works for our use case and avoids the usage of reflection (so it's compatible with Quarkus native if in the future we want to use it).

The drawback is that it lacks many features that regular expression parsers have like conditional expressions and many others.

Another alternative to SPeL expressions and Quarkus Qute is to use Mvel2 (which is supported by JBoss RedHat team). This framework works in Spring Boot and Quarkus, but not in Quarkus native, see the Quarkus example I created for this - use mvn clean install from the mvel2 directory and mvn clean install -Dnative to run the test using the native binaries and you can see the test will fail).

Moreover, because of using Mvel2 or Qute (or any other expression parsers), we would need to update all the properties to accommodate the new conventions (for example, instead of using #{metric.id}, we need to use @{metric.id} in Mvel2.

Therefore, using this very simple solution, it works in Quarkus native (because it does not use reflection), also it does not require changes and it's very well performant (because of the same, neither uses reflection nor requires adding an additional dependency).

@Sgitario Sgitario added the QE Unneeded Pull request does not need QE approval label Oct 5, 2023
import org.springframework.stereotype.Component;

/** Builds PromQL queries based on a configured template. */
@Component
public class QueryBuilder {

private static final Logger log = LoggerFactory.getLogger(QueryBuilder.class);
private static final Logger LOGGER = LoggerFactory.getLogger(QueryBuilder.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just use log. That's what Lombok generates and I'd like to remain consistent across the codebase. In fact, just dropping an @Slf4j annotation on this class seems like the best thing to do. We haven't gone back and done that everywhere (you'll see it used some but not consistently) but it seems like the most sensible thing to do going forward.

String defaultValue = null;
if (rawKey.contains(SYSTEM_PROPERTY_DEFAULT_TAG)) {
String[] keyParts = rawKey.split(SYSTEM_PROPERTY_DEFAULT_TAG);
key = keyParts[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to do some checks here. Specifically, require key to begin with an metric prefix (and maybe need to add runtime as well?). Giving this class unfettered access to the system properties and environment variables can have security implications. I think it would be safer to just eliminate access to any property or environment variable that doesn't start with a blessed prefix.

Copy link
Contributor Author

@Sgitario Sgitario Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's agree first if this is the right approach or not. I'm in favor of getting rid of the system properties usage altogether.
We have a meeting today to discuss the approach to use to replace the SPeL expression parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After speaking with the team, we agreed to use this approach. I've already removed the support of system properties.

@Sgitario Sgitario merged commit 2b85bd4 into RedHatInsights:main Oct 17, 2023
6 checks passed
@Sgitario Sgitario deleted the refactor_query_builder branch October 17, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QE Unneeded Pull request does not need QE approval
Projects
None yet
3 participants