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

feat: search in service logs #1830

Merged
merged 9 commits into from
Nov 20, 2023
Merged

feat: search in service logs #1830

merged 9 commits into from
Nov 20, 2023

Conversation

adschwartz
Copy link
Contributor

Description:

Adding a search bar to the service logs window
image

Is this change user facing?

YES

References (if applicable):

Closes #1791

Anders Schwartz added 5 commits November 16, 2023 19:07
Anders Schwartz added 2 commits November 20, 2023 12:06
# Conflicts:
#	engine/server/webapp/asset-manifest.json
#	engine/server/webapp/index.html
#	engine/server/webapp/static/js/main.045e0a73.js.LICENSE.txt
#	engine/server/webapp/static/js/main.045e0a73.js.map
#	engine/server/webapp/static/js/main.14d7f9cc.js.LICENSE.txt
#	engine/server/webapp/static/js/main.14d7f9cc.js.map
#	engine/server/webapp/static/js/main.9e07637a.js
#	engine/server/webapp/static/js/main.9e07637a.js.LICENSE.txt
#	engine/server/webapp/static/js/main.9e07637a.js.map
@adschwartz adschwartz added this pull request to the merge queue Nov 20, 2023
Merged via the queue into main with commit 7fce5b5 Nov 20, 2023
33 checks passed
@adschwartz adschwartz deleted the anders/search branch November 20, 2023 17:57
github-merge-queue bot pushed a commit that referenced this pull request Nov 20, 2023
🤖 I have created a release *beep* *boop*
---


##
[0.85.33](0.85.32...0.85.33)
(2023-11-20)


### Features

* search in service logs
([#1830](#1830))
([7fce5b5](7fce5b5)),
closes [#1791](#1791)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: kurtosisbot <kurtosisbot@users.noreply.github.com>
Copy link
Contributor

@Dartoxian Dartoxian left a comment

Choose a reason for hiding this comment

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

Nice job getting this out - I expect a decent amount of the feedback I've left here you're already aware of. The main piece of feedback I have is a strong preference to avoid chains of useEffect in response to callbacks - they make code harder to read and can eventually introduce bugs that are hard to trace. React has some notes on how to identify and remove avoidable effects here https://react.dev/learn/you-might-not-need-an-effect

Comment on lines +26 to -20
export type LogLineInput = {
logLineProps: LogLineProps;
logLineSearch?: LogLineSearch;
selected: boolean | undefined;
};

const logFontFamily = "Menlo, Monaco, Inconsolata, Consolas, Courier, monospace";

export const LogLine = ({ timestamp, message, status }: LogLineProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here LogLineProps should have just become:

export type LogLineProps = {
      timestamp?: DateTime;
      message?: string;
      status?: LogStatus;
      selected?: boolean;
      logLineSearch?: LogLineSearch;
}

Comment on lines +61 to +69
const HighlightPattern = ({
text,
regex,
selected,
}: {
text: string;
regex: RegExp;
selected: boolean | undefined;
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this component (because that's what it is) should be inlined with LogLineSearch - this means it's redefined on every render and defined for every LogLine. I think it's LogLine specific enough to just be another non exported component in this file.

const processText = (message: string) => {
if (hasAnsi(message)) {
return parse(convert.toHtml(message));
const processText = (text: string, selected: boolean | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is also actually another react component - it should be moved out of the LogLine component and given a better name as a (non exported) component like Message

@@ -4,6 +4,9 @@ import { DateTime } from "luxon";
import { isDefined } from "../../../utils";
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this - lets not use has-ansi (or its dependency ansi-regex) at all and just inline the code in src/utils/index.ts (and combine it with stripAnsi):

export function ansiRegex({ onlyFirst = false } = {}) {
  const pattern = [
    "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
    "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
  ].join("|");

  return new RegExp(pattern, onlyFirst ? undefined : "g");
}

const regex = ansiRegex({ onlyFirst: true });

export function hasAnsi(text: string) {
  return regex.test(text);
}

@@ -4,6 +4,9 @@ import { DateTime } from "luxon";
import { isDefined } from "../../../utils";
// @ts-ignore
import hasAnsi from "has-ansi";
import { ReactElement } from "react";
import { normalizeLogText } from "./LogViewer";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a circular dependency now between LogLine and LogViewer - this should be avoided, and this method should be moved to a utils file.

const searchTerm = normalizeLogText(rawText);
const logLineSearch: LogLineSearch = {
searchTerm: searchTerm,
pattern: new RegExp(searchTerm, "gi"), // `i` is invariant case
Copy link
Contributor

Choose a reason for hiding this comment

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

i is case insensitive

Comment on lines +131 to +132
if (!search) return false;
return isDefined(search.searchTerm) && isNotEmpty(search.searchTerm);
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit):

return isDefined(search?.searchTerm) && isNotEmpty(search.searchTerm);

debouncedUpdateSearchTermCallback(e.target.value);
};

const priorMatch = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

(very minor) wasn't immediately obvious to me this is a function - should be named something like handlePriorMatchClick

Comment on lines +179 to +183
useEffect(() => {
if (virtuosoRef?.current && currentSearchIndex !== undefined && currentSearchIndex >= 0) {
virtuosoRef.current.scrollToIndex(searchMatchesIndices[currentSearchIndex]);
}
}, [currentSearchIndex]);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be a useEffect and should probably be either in a callback or called direct from the navigation/find matches code.

Comment on lines +241 to +249
<Editable
p={0}
m={0}
size={"sm"}
value={`${currentSearchIndex + 1}`}
onChange={(inputString) =>
updateSearchIndexBounded(parseMatchIndexRequest(inputString) - 1)
}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with this component, but wondering if we can apply numeric constraint to it.

github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2023
## Description:
This PR includes a number or emui enhancements:
* Artifacts view
* fix to dict/list input sizes
* Update logging ui to match designs
* Update general app layout to match designs (headers)

Additionally the feedback left on
#1830 is implemented.

### Demo of the artifacts view


https://github.com/kurtosis-tech/kurtosis/assets/4419574/0849e46e-c410-4a07-a65f-bcc74297c53b

## Is this change user facing?
YES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloud: unable to find all occurrences of searched item in logs
3 participants