Skip to content

Commit

Permalink
chore(text): specify CEL as the language spec for match expression (c…
Browse files Browse the repository at this point in the history
…ryostatio#1353)

Signed-off-by: Thuan Vo <[email protected]>
  • Loading branch information
tthvo authored Sep 16, 2024
1 parent d9dac62 commit bf9d953
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
pull_request:
branches:
- main
- pf5 # TODO remove after merge
- feature-.+
- v[0-9]+
- v[0-9]+.[0-9]+
Expand Down
4 changes: 2 additions & 2 deletions locales/en/public.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
},
"EVALUATING_EXPRESSION": "Evaluating Match Expression...",
"FAILING_EVALUATION": "The expression matching failed.",
"MATCH_EXPRESSION_HELPER_TEXT": "Enter a Match Expression. This is a Java-like code snippet that is evaluated against each target application to determine whether the rule should be applied.",
"MATCH_EXPRESSION_HELPER_TEXT": "Enter a Match Expression. This is a <a>Common Expression Language (CEL)</a> code snippet that is evaluated against each target application to determine whether the rule should be applied.",
"MATCH_EXPRESSION_HINT_BODY": "Try an expression like:",
"MATCH_EXPRESSION_HINT_MODAL_HEADER": "Match Expression hint",
"MODAL_DESCRIPTION": "Create Stored Credentials for target JVMs. Cryostat will use these credentials to connect to Cryostat agents or target JVMs over JMX (if required).",
Expand All @@ -215,7 +215,7 @@
"EVALUATING_EXPRESSION": "Evaluating Match Expression...",
"FAILING_EVALUATION": "The expression matching failed.",
"INITIAL_DELAY_HELPER_TEXT": "Initial delay before archiving starts. The first archived copy will be made this long after the Recording is started. The second archived copy will occur one Archival period later.",
"MATCH_EXPRESSION_HELPER_TEXT": "Enter a Match Expression. This is a Java-like code snippet that is evaluated against each target application to determine whether the rule should be applied.",
"MATCH_EXPRESSION_HELPER_TEXT": "Enter a Match Expression. This is a <a>Common Expression Language (CEL)</a> code snippet that is evaluated against each target application to determine whether the rule should be applied.",
"MATCH_EXPRESSION_HINT_BODY": "Try an expression like:",
"MATCH_EXPRESSION_HINT_MODAL_HEADER": "Match Expression hint",
"MAXAGE_HELPER_TEXT": "The maximum age of Recording data retained in the target application's Recording buffer.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CEL_SPEC_HREF } from '@app/Rules/utils';
import { FeatureLevel } from '@app/Shared/Services/service.types';
import { QuickStart } from '@patternfly/quickstarts';
import { CryostatIcon, conclusion } from '../quickstart-utils';
Expand Down Expand Up @@ -64,7 +65,7 @@ Automated Rules are configurations that instruct [APP] to create JDK Flight Reco
description: `
To create a new rule, use the Automated Rule creation form to fill in the required fields.
The [Match Expression]{{highlight rule-matchexpr}} field is a Java-like code snippet that is matched against each Target JVM. This allows you to create rules that run on specific target JVMs. For example, you can create a rule that runs on all target JVMs with the Match Expression: \`true\`{{copy}}. You can also match targets more specifically with a Match Expression like \`target.annotations.cryostat['PORT'] == 9091\`{{copy}}, which will match targets that are connected to [APP] on port 9091.
The [Match Expression]{{highlight rule-matchexpr}} field is a <a target="_blank" href="${CEL_SPEC_HREF}">Common Expression Language (CEL)</a> code snippet that is matched against each Target JVM. This allows you to create rules that run on specific target JVMs. For example, you can create a rule that runs on all target JVMs with the Match Expression: \`true\`{{copy}}. You can also match targets more specifically with a Match Expression like \`target.annotations.cryostat['PORT'] == 9091\`{{copy}}, which will match targets that are connected to [APP] on port 9091.
To create a new rule, you must fill out the following required fields:
Expand Down
22 changes: 13 additions & 9 deletions src/app/Rules/CreateRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ import {
import { HelpIcon } from '@patternfly/react-icons';
import _ from 'lodash';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { combineLatest, forkJoin, iif, of, Subject } from 'rxjs';
import { catchError, debounceTime, map, switchMap, tap } from 'rxjs/operators';
import { RuleFormData } from './types';
import { isRuleNameValid } from './utils';
import { CEL_SPEC_HREF, isRuleNameValid } from './utils';

export interface CreateRuleFormProps {}

Expand Down Expand Up @@ -433,13 +433,17 @@ export const CreateRuleForm: React.FC<CreateRuleFormProps> = (_props) => {
<FormHelperText>
<HelperText>
<HelperTextItem variant={formData.matchExpressionValid}>
{evaluating
? t('CreateRule.EVALUATING_EXPRESSION')
: formData.matchExpressionValid === ValidatedOptions.warning
? t('CreateRule.WARNING_NO_MATCH')
: formData.matchExpressionValid === ValidatedOptions.error
? t('CreateRule.FAILING_EVALUATION')
: t('CreateRule.MATCH_EXPRESSION_HELPER_TEXT')}
{evaluating ? (
t('CreateRule.EVALUATING_EXPRESSION')
) : formData.matchExpressionValid === ValidatedOptions.warning ? (
t('CreateRule.WARNING_NO_MATCH')
) : formData.matchExpressionValid === ValidatedOptions.error ? (
t('CreateRule.FAILING_EVALUATION')
) : (
<Trans t={t} components={{ a: <a target="_blank" href={CEL_SPEC_HREF} /> }}>
CreateRule.MATCH_EXPRESSION_HELPER_TEXT
</Trans>
)}
</HelperTextItem>
</HelperText>
</FormHelperText>
Expand Down
2 changes: 2 additions & 0 deletions src/app/Rules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const isRule = (obj: object): boolean => {
export const RuleNamePattern = /^[\w_]+$/;

export const isRuleNameValid = (name: string) => RuleNamePattern.test(name);

export const CEL_SPEC_HREF = 'https://github.com/google/cel-spec/blob/master/doc/langdef.md';
21 changes: 13 additions & 8 deletions src/app/SecurityPanel/Credentials/CreateCredentialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import { AuthCredential, CredentialAuthForm } from '@app/AppLayout/CredentialAuthForm';
import { CEL_SPEC_HREF } from '@app/Rules/utils';
import { MatchExpressionHint } from '@app/Shared/Components/MatchExpression/MatchExpressionHint';
import { MatchExpressionVisualizer } from '@app/Shared/Components/MatchExpression/MatchExpressionVisualizer';
import { Target } from '@app/Shared/Services/api.types';
Expand Down Expand Up @@ -45,7 +46,7 @@ import {
} from '@patternfly/react-core';
import { FlaskIcon, HelpIcon, TopologyIcon } from '@patternfly/react-icons';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';
import { catchError, combineLatest, distinctUntilChanged, interval, map, of, switchMap, tap } from 'rxjs';
import { CredentialTestTable } from './CredentialTestTable';
import { TestRequest } from './types';
Expand Down Expand Up @@ -263,13 +264,17 @@ export const AuthForm: React.FC<AuthFormProps> = ({ onDismiss, onPropsSave, prog
<FormHelperText>
<HelperText>
<HelperTextItem variant={matchExpressionValid}>
{evaluating
? t('CreateCredentialModal.EVALUATING_EXPRESSION')
: matchExpressionValid === ValidatedOptions.warning
? t('CreateCredentialModal.WARNING_NO_MATCH')
: matchExpressionValid === ValidatedOptions.error
? t('CreateCredentialModal.FAILING_EVALUATION')
: t('CreateCredentialModal.MATCH_EXPRESSION_HELPER_TEXT')}
{evaluating ? (
t('CreateCredentialModal.EVALUATING_EXPRESSION')
) : matchExpressionValid === ValidatedOptions.warning ? (
t('CreateCredentialModal.WARNING_NO_MATCH')
) : matchExpressionValid === ValidatedOptions.error ? (
t('CreateCredentialModal.FAILING_EVALUATION')
) : (
<Trans t={t} components={{ a: <a target="_blank" href={CEL_SPEC_HREF} /> }}>
CreateRule.MATCH_EXPRESSION_HELPER_TEXT
</Trans>
)}
</HelperTextItem>
</HelperText>
</FormHelperText>
Expand Down

0 comments on commit bf9d953

Please sign in to comment.