You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by nickwallen <gi...@git.apache.org> on 2017/08/18 17:46:33 UTC
[GitHub] metron pull request #707: METRON-1121 Ignore Profile with Bad 'init', 'updat...
GitHub user nickwallen opened a pull request:
https://github.com/apache/metron/pull/707
METRON-1121 Ignore Profile with Bad 'init', 'update' or 'groupBy'
The Profiler needs to gracefully ignore profiles that have a bad 'init', 'update', or 'groupBy' expression. Under certain conditions a message may not be applied to all valid profiles, due to a single bad profile.
If the Profiler is running with multiple profiles defined and one of those profiles has a Stellar expression that throws an exception for either the 'init', 'update', or 'groupBy', the current logic will not continue to attempt to apply the message to the remaining valid profiles. Only valid profiles executed before the bad profile will have the message applied.
## Testing
Unit tests have been added to check for these conditions. This can be manually tested with either a live Profiler running in a cluster or using the Profiler debugging functions.
Create two profiles; one that is valid and another that is invalid, like the following. Ensure that all test messages that are sent through the Profiler, reach the `good-profile` despite the `bad-profile`.
```
{
"profiles": [
{
"profile": "bad-profile",
"foreach": "ip_src_addr",
"init": { "x": "2 / 0" },
"update": { "x": "x + 1" },
"result": "x"
},
{
"profile": "good-profile",
"foreach": "ip_src_addr",
"init": { "x": "0" },
"update": { "x": "x + 1" },
"result": "x"
}
]
}
```
## Pull Request Checklist
- [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
- [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
- [x] Have you included steps or a guide to how the change may be verified and tested manually?
- [x] Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:
- [x] Have you written or updated unit tests and or integration tests to verify your changes?
- [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [x] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
- [x] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`:
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nickwallen/metron METRON-1121
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/metron/pull/707.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #707
----
commit 5579748ad4336a7c1a15c319d59fd6cbdeb6531e
Author: Nick Allen <ni...@nickallen.org>
Date: 2017-08-18T17:37:01Z
METRON-1121 Ignore Profile with Bad 'init', 'update' or 'groupBy'
commit 893b7db84f155ea6af975ee51338f39b763eaedb
Author: Nick Allen <ni...@nickallen.org>
Date: 2017-08-18T17:45:50Z
Rm errant comment
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #707: METRON-1121 Ignore Profile with Bad 'init', 'updat...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/metron/pull/707
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #707: METRON-1121 Ignore Profile with Bad 'init', 'update' or '...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/707
Yep, +1 by inspection, thanks!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #707: METRON-1121 Ignore Profile with Bad 'init', 'updat...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/707#discussion_r134758959
--- Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/DefaultProfileBuilder.java ---
@@ -253,7 +265,8 @@ private void assign(Map<String, String> expressions, Map<String, Object> transie
.forEach((expr) -> results.add(executor.execute(expr, transientState, Object.class)));
} catch (Throwable e) {
- String msg = format("Bad '%s' expression: %s, profile=%s, entity=%s", expressionType, e.getMessage(), profileName, entity);
+ String msg = format("Bad '%s' expression: error=%s, profile=%s, entity=%s", expressionType, e.getMessage(), profileName, entity);
+ LOG.error(msg);
--- End diff --
Can you pass `e` as the second argument to `LOG.error`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #707: METRON-1121 Ignore Profile with Bad 'init', 'update' or '...
Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:
https://github.com/apache/metron/pull/707
Good eye, @cestella . Latest commit is catching Throwable and logging e's.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #707: METRON-1121 Ignore Profile with Bad 'init', 'updat...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/707#discussion_r134758686
--- Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/DefaultProfileBuilder.java ---
@@ -140,33 +144,41 @@ public void apply(JSONObject message) {
* @return Returns the completed profile measurement.
*/
@Override
- public ProfileMeasurement flush() {
+ public Optional<ProfileMeasurement> flush() {
LOG.debug("Flushing profile: profile={}, entity={}", profileName, entity);
+ Optional<ProfileMeasurement> result = Optional.empty();
- // execute the 'profile' expression(s)
- @SuppressWarnings("unchecked")
- Object profileValue = execute(definition.getResult().getProfileExpressions().getExpression(), "result/profile");
-
- // execute the 'triage' expression(s)
- Map<String, Object> triageValues = definition.getResult().getTriageExpressions().getExpressions()
- .entrySet()
- .stream()
- .collect(Collectors.toMap(
- e -> e.getKey(),
- e -> execute(e.getValue(), "result/triage")));
-
- // execute the 'groupBy' expression(s) - can refer to value of 'result' expression
- List<Object> groups = execute(definition.getGroupBy(), ImmutableMap.of("result", profileValue), "groupBy");
+ try {
+ // execute the 'profile' expression(s)
+ Object profileValue = execute(definition.getResult().getProfileExpressions().getExpression(), "result/profile");
+
+ // execute the 'triage' expression(s)
+ Map<String, Object> triageValues = definition.getResult().getTriageExpressions().getExpressions()
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ e -> e.getKey(),
+ e -> execute(e.getValue(), "result/triage")));
+
+ // execute the 'groupBy' expression(s) - can refer to value of 'result' expression
+ List<Object> groups = execute(definition.getGroupBy(), ImmutableMap.of("result", profileValue), "groupBy");
+
+ result = Optional.of(new ProfileMeasurement()
+ .withProfileName(profileName)
+ .withEntity(entity)
+ .withGroups(groups)
+ .withPeriod(clock.currentTimeMillis(), periodDurationMillis, TimeUnit.MILLISECONDS)
+ .withProfileValue(profileValue)
+ .withTriageValues(triageValues)
+ .withDefinition(definition));
+
+ } catch(Exception e) {
--- End diff --
Should this be a Throwable?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #707: METRON-1121 Ignore Profile with Bad 'init', 'updat...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/707#discussion_r134758762
--- Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/DefaultProfileBuilder.java ---
@@ -140,33 +144,41 @@ public void apply(JSONObject message) {
* @return Returns the completed profile measurement.
*/
@Override
- public ProfileMeasurement flush() {
+ public Optional<ProfileMeasurement> flush() {
LOG.debug("Flushing profile: profile={}, entity={}", profileName, entity);
+ Optional<ProfileMeasurement> result = Optional.empty();
- // execute the 'profile' expression(s)
- @SuppressWarnings("unchecked")
- Object profileValue = execute(definition.getResult().getProfileExpressions().getExpression(), "result/profile");
-
- // execute the 'triage' expression(s)
- Map<String, Object> triageValues = definition.getResult().getTriageExpressions().getExpressions()
- .entrySet()
- .stream()
- .collect(Collectors.toMap(
- e -> e.getKey(),
- e -> execute(e.getValue(), "result/triage")));
-
- // execute the 'groupBy' expression(s) - can refer to value of 'result' expression
- List<Object> groups = execute(definition.getGroupBy(), ImmutableMap.of("result", profileValue), "groupBy");
+ try {
+ // execute the 'profile' expression(s)
+ Object profileValue = execute(definition.getResult().getProfileExpressions().getExpression(), "result/profile");
+
+ // execute the 'triage' expression(s)
+ Map<String, Object> triageValues = definition.getResult().getTriageExpressions().getExpressions()
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ e -> e.getKey(),
+ e -> execute(e.getValue(), "result/triage")));
+
+ // execute the 'groupBy' expression(s) - can refer to value of 'result' expression
+ List<Object> groups = execute(definition.getGroupBy(), ImmutableMap.of("result", profileValue), "groupBy");
+
+ result = Optional.of(new ProfileMeasurement()
+ .withProfileName(profileName)
+ .withEntity(entity)
+ .withGroups(groups)
+ .withPeriod(clock.currentTimeMillis(), periodDurationMillis, TimeUnit.MILLISECONDS)
+ .withProfileValue(profileValue)
+ .withTriageValues(triageValues)
+ .withDefinition(definition));
+
+ } catch(Exception e) {
+ // if any of the Stellar expressions fail, a measurement should NOT be returned
+ LOG.error(format("Unable to flush profile: %s", e.getMessage()));
--- End diff --
Can we pass the exception as the second argument to `LOG.error`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #707: METRON-1121 Ignore Profile with Bad 'init', 'update' or '...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/707
+1 by inspection
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---