Skip to content

Commit

Permalink
Update CEL info
Browse files Browse the repository at this point in the history
  • Loading branch information
Haarolean committed Feb 27, 2024
1 parent 8298929 commit b47aa33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void canCheckKeyAsJsonObjectIfItCanBeParsedToJson() {

@Test
void keySetToKeyStringIfCantBeParsedToJson() {
var f = celScriptFilter("has(record.keyAsText) && record.keyAsText == 'not json' && record.key == 'not json'");
var f = celScriptFilter("has(record.keyAsText) && record.keyAsText == 'not json' && record.key == 'not json'"); // TODO this one is weird
assertTrue(f.test(msg().key("not json")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,16 @@ export const ListItem = styled.li`
color: ${({ theme }) => theme.table.td.color.normal};
`;

export const InfoHeading = styled.div`
font-size: 16px;
font-weight: 500;
line-height: 1.5;
margin-bottom: 10px;
color: ${({ theme }) => theme.table.td.color.normal};
`;

export const InfoParagraph = styled.div`
font-size: 12px;
font-size: 14px;
font-weight: 400;
line-height: 1.5;
margin-bottom: 10px;
Expand Down
53 changes: 24 additions & 29 deletions frontend/src/components/Topics/Topic/Messages/Filters/InfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,50 @@ interface InfoModalProps {
const InfoModal: React.FC<InfoModalProps> = ({ toggleIsOpen }) => {
return (
<S.InfoModal>
<S.InfoHeading>We use CEL syntax for smart message filters</S.InfoHeading>
<S.InfoParagraph>
<b>Variables bound to groovy context:</b> partition, timestampMs,
keyAsText, valueAsText, header, key (json if possible), value (json if
possible).
<b>Variables bound to the context:</b>
</S.InfoParagraph>
<ol aria-label="info-list">
<S.ListItem>key (json if possible)</S.ListItem>
<S.ListItem>value (json if possible)</S.ListItem>
<S.ListItem>keyAsText</S.ListItem>
<S.ListItem>valueAsText</S.ListItem>
<S.ListItem>header</S.ListItem>
<S.ListItem>partition</S.ListItem>
<S.ListItem>timestampMs</S.ListItem>
</ol>
<S.InfoParagraph>
<b>JSON parsing logic:</b>
</S.InfoParagraph>
<S.InfoParagraph>
Key and Value (if they can be parsed to JSON) they are bound as JSON
objects, otherwise bound as nulls.
Key and Value (if parsing to JSON is available) are bound as JSON
objects, otherwise as nulls.
</S.InfoParagraph>
<S.InfoParagraph>
<b>Sample filters:</b>
<b>Filter examples:</b>
</S.InfoParagraph>
<ol aria-label="info-list">
<S.ListItem>
<code>keyAsText != null && keyAsText ~&quot;([Gg])roovy&quot;</code> -
regex for key as a string
</S.ListItem>
<S.ListItem>
<code>
value.name == &quot;iS.ListItemax&quot; && value.age &gt; 30
has(record.keyAsText) &&
record.keyAsText.matches(&quot;.*[Gg]roovy.*&quot;)
</code>{' '}
- in case value is json
- regex for key as a string
</S.ListItem>
<S.ListItem>
<code>value == null && valueAsText != null</code> - search for values
that are not nulls and are not json
<code>
has(record.key.name.first) && record.key.name.first ==
&apos;user1&apos;
</code>{' '}
- in case if the value is json
</S.ListItem>
<S.ListItem>
<code>
headers.sentBy == &quot;some system&quot; &&
headers[&quot;sentAt&quot;] == &quot;2020-01-01&quot;
record.headers.size() == 1 && !has(record.headers.k1) &&
record.headers[&apos;k2&apos;] == &apos;v2&apos;
</code>
</S.ListItem>
<S.ListItem>
multiline filters are also allowed:
<S.InfoParagraph>
<pre>
def name = value.name
<br />
def age = value.age
<br />
name == &quot;iliax&quot; && age == 30
<br />
</pre>
</S.InfoParagraph>
</S.ListItem>
</ol>
<S.ButtonContainer>
<Button
Expand Down

0 comments on commit b47aa33

Please sign in to comment.