This is an automated email from the ASF dual-hosted git repository.
xhsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new c88845a [TE] frontend - harleyjj/jsyaml - add jsyaml package to parse
valid yaml as secondary to yamljs (#4480)
c88845a is described below
commit c88845a448d37c063134325ddbcc687a4e9c2784
Author: Harley Jackson <[email protected]>
AuthorDate: Mon Aug 5 10:22:17 2019 -0700
[TE] frontend - harleyjj/jsyaml - add jsyaml package to parse valid yaml as
secondary to yamljs (#4480)
---
.../thirdeye-frontend/app/pods/anomalies/controller.js | 14 ++++++++++++--
.../app/pods/components/detection-yaml/component.js | 11 +++++++++--
.../thirdeye-frontend/app/pods/manage/explore/route.js | 13 ++++++++++++-
thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js | 13 ++++++++++++-
thirdeye/thirdeye-frontend/ember-cli-build.js | 7 +++++++
thirdeye/thirdeye-frontend/package.json | 1 +
thirdeye/thirdeye-frontend/yarn.lock | 8 ++++++++
7 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/thirdeye/thirdeye-frontend/app/pods/anomalies/controller.js
b/thirdeye/thirdeye-frontend/app/pods/anomalies/controller.js
index f2bc02b..30ea2af 100644
--- a/thirdeye/thirdeye-frontend/app/pods/anomalies/controller.js
+++ b/thirdeye/thirdeye-frontend/app/pods/anomalies/controller.js
@@ -15,6 +15,7 @@ import { inject as service } from '@ember/service';
import { isPresent, isEmpty } from '@ember/utils';
import Controller from '@ember/controller';
import yamljs from 'yamljs';
+import jsyaml from 'js-yaml';
import { reads } from '@ember/object/computed';
import { toastOptions } from 'thirdeye-frontend/utils/constants';
import { setUpTimeRangeOptions, powerSort } from
'thirdeye-frontend/utils/manage-alert-utils';
@@ -398,14 +399,23 @@ export default Controller.extend({
let additionalAlertNames = [];
// for each group, grab yaml, extract alert names for adding to filterObj
selectedSubGroupObjects.forEach(group => {
+ let yamlAsObject;
try {
- const yamlAsObject = yamljs.parse(group.get('yaml'));
+ yamlAsObject = yamljs.parse(group.get('yaml'));
if (Array.isArray(yamlAsObject.subscribedDetections)) {
additionalAlertNames = [ ...additionalAlertNames,
...yamlAsObject.subscribedDetections];
}
}
catch(error){
- notifications.error(`Failed to retrieve alert names for subscription
group: ${group.get('name')}`, 'Error', toastOptions);
+ try {
+ // use jsyaml package to try parsing again, since yamljs doesn't
parse some edge cases
+ yamlAsObject = jsyaml.safeLoad(group.get('yaml'));
+ if (Array.isArray(yamlAsObject.subscribedDetections)) {
+ additionalAlertNames = [ ...additionalAlertNames,
...yamlAsObject.subscribedDetections];
+ }
+ } catch (error) {
+ notifications.error(`Failed to retrieve alert names for
subscription group: ${group.get('name')}`, 'Error', toastOptions);
+ }
}
});
// add the alert names extracted from groups to any that are already
present
diff --git
a/thirdeye/thirdeye-frontend/app/pods/components/detection-yaml/component.js
b/thirdeye/thirdeye-frontend/app/pods/components/detection-yaml/component.js
index 9121641..f23b3a2 100644
--- a/thirdeye/thirdeye-frontend/app/pods/components/detection-yaml/component.js
+++ b/thirdeye/thirdeye-frontend/app/pods/components/detection-yaml/component.js
@@ -20,6 +20,7 @@ import {computed, set, get, getProperties, setProperties}
from '@ember/object';
import {checkStatus} from 'thirdeye-frontend/utils/utils';
import {yamlAlertProps, toastOptions} from 'thirdeye-frontend/utils/constants';
import yamljs from 'yamljs';
+import jsyaml from 'js-yaml';
import RSVP from "rsvp";
import fetch from 'fetch';
import {
@@ -211,8 +212,14 @@ export default Component.extend({
set(this, 'isYamlParseable', true);
}
catch(err){
- set(this, 'isYamlParseable', false);
- return noResultsArray;
+ try {
+ // use jsyaml package to try parsing again, since yamljs doesn't
parse some edge cases
+ yamlAsObject = jsyaml.safeLoad(detectionYaml);
+ set(this, 'isYamlParseable', true);
+ } catch (error) {
+ set(this, 'isYamlParseable', false);
+ return noResultsArray;
+ }
}
// if editor.metricId field contains a value, metric was just chosen.
Populate caches for filters and dimensions
if(editor.metricId){
diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
b/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
index a750a16..80ba3b0 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/explore/route.js
@@ -10,6 +10,7 @@ import { inject as service } from '@ember/service';
import { toastOptions } from 'thirdeye-frontend/utils/constants';
import { formatYamlFilter } from 'thirdeye-frontend/utils/utils';
import yamljs from 'yamljs';
+import jsyaml from 'js-yaml';
import moment from 'moment';
import AuthenticatedRouteMixin from
'ember-simple-auth/mixins/authenticated-route-mixin';
@@ -37,7 +38,17 @@ export default Route.extend(AuthenticatedRouteMixin, {
notifications.error('Retrieval of alert yaml failed.', 'Error',
toastOptions);
} else {
if (detection_json.yaml) {
- const detectionInfo = yamljs.parse(detection_json.yaml);
+ let detectionInfo;
+ try {
+ detectionInfo = yamljs.parse(detection_json.yaml);
+ } catch (error) {
+ try {
+ // use jsyaml package to try parsing again, since yamljs doesn't
parse some edge cases
+ detectionInfo = jsyaml.safeLoad(detection_json.yaml);
+ } catch (error) {
+ throw new Error('yaml parsing error');
+ }
+ }
const lastDetection = new Date(detection_json.lastTimestamp);
Object.assign(detectionInfo, {
isActive: detection_json.active,
diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
b/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
index 119f11d..a3ccf3c 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/yaml/route.js
@@ -8,6 +8,7 @@ import RSVP from 'rsvp';
import { set, get } from '@ember/object';
import { inject as service } from '@ember/service';
import yamljs from 'yamljs';
+import jsyaml from 'js-yaml';
import moment from 'moment';
import { yamlAlertSettings, toastOptions } from
'thirdeye-frontend/utils/constants';
import { formatYamlFilter } from 'thirdeye-frontend/utils/utils';
@@ -39,7 +40,17 @@ export default Route.extend(AuthenticatedRouteMixin, {
notifications.error('Retrieval of alert yaml failed.', 'Error',
toastOptions);
} else {
if (detection_json.yaml) {
- const detectionInfo = yamljs.parse(detection_json.yaml);
+ let detectionInfo;
+ try {
+ detectionInfo = yamljs.parse(detection_json.yaml);
+ } catch (error) {
+ try {
+ // use jsyaml package to try parsing again, since yamljs doesn't
parse some edge cases
+ detectionInfo = jsyaml.safeLoad(detection_json.yaml);
+ } catch (error) {
+ throw new Error('yaml parsing error');
+ }
+ }
const lastDetection = new Date(detection_json.lastTimestamp);
Object.assign(detectionInfo, {
isActive: detection_json.active,
diff --git a/thirdeye/thirdeye-frontend/ember-cli-build.js
b/thirdeye/thirdeye-frontend/ember-cli-build.js
index 6149e37..5513a5b 100644
--- a/thirdeye/thirdeye-frontend/ember-cli-build.js
+++ b/thirdeye/thirdeye-frontend/ember-cli-build.js
@@ -75,6 +75,13 @@ module.exports = function(defaults) {
]
});
+ // imports yamljs node module as commonjs
+ app.import('node_modules/js-yaml/index.js', {
+ using: [
+ { transformation: 'cjs', as: 'js-yaml'}
+ ]
+ });
+
// Use `app.import` to add additional libraries to the generated
// output files.
diff --git a/thirdeye/thirdeye-frontend/package.json
b/thirdeye/thirdeye-frontend/package.json
index 2851b1d..1947029 100644
--- a/thirdeye/thirdeye-frontend/package.json
+++ b/thirdeye/thirdeye-frontend/package.json
@@ -91,6 +91,7 @@
"ember-cryptojs-shim": "^4.3.0",
"ember-simple-tree": "^0.4.2",
"ion-rangeslider": "^2.2.0",
+ "js-yaml": "^3.13.1",
"moment": "^2.18.1",
"yamljs": "^0.3.0"
}
diff --git a/thirdeye/thirdeye-frontend/yarn.lock
b/thirdeye/thirdeye-frontend/yarn.lock
index ae56ddb..904c2a1 100644
--- a/thirdeye/thirdeye-frontend/yarn.lock
+++ b/thirdeye/thirdeye-frontend/yarn.lock
@@ -4974,6 +4974,14 @@ js-yaml@^3.12.0, js-yaml@^3.2.5, js-yaml@^3.2.7,
js-yaml@^3.3.0, js-yaml@^3.9.1:
argparse "^1.0.7"
esprima "^4.0.0"
+js-yaml@^3.13.1:
+ version "3.13.1"
+ resolved
"https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
+ integrity
sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
+ dependencies:
+ argparse "^1.0.7"
+ esprima "^4.0.0"
+
jsbn@~0.1.0:
version "0.1.1"
resolved
"https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]