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(ui): Filterable pod logs #5319

Merged
merged 6 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@
"type": "string",
"name": "untilTime",
"in": "query"
},
{
"type": "string",
"name": "filter",
"in": "query"
}
],
"responses": {
Expand Down
319 changes: 186 additions & 133 deletions pkg/apiclient/application/application.pb.go

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,23 @@ func (s *Server) PodLogs(q *application.ApplicationPodLogsQuery, ws application.
if q.TailLines > 0 {
tailLines = &q.TailLines
}

type filterData struct {
rbreeze marked this conversation as resolved.
Show resolved Hide resolved
literal string
inverse bool
}

filter := filterData{
literal: "",
inverse: false,
}
if q.Filter != nil {
filter.literal = *q.Filter
if filter.literal[0] == '!' {
filter.literal = filter.literal[1:]
filter.inverse = true
}
}
stream, err := kubeClientset.CoreV1().Pods(pod.Namespace).GetLogs(*q.PodName, &v1.PodLogOptions{
Container: q.Container,
Follow: q.Follow,
Expand Down Expand Up @@ -1118,6 +1135,12 @@ func (s *Server) PodLogs(q *application.ApplicationPodLogsQuery, ws application.
close(done)
return
}
if q.Filter != nil {
rbreeze marked this conversation as resolved.
Show resolved Hide resolved
lineContainsFilter := strings.Contains(line, filter.literal)
if (filter.inverse && lineContainsFilter) || (!filter.inverse && !lineContainsFilter) {
continue
}
}
err = ws.Send(&application.LogEntry{
Content: line,
TimeStamp: metaLogTime,
Expand Down
1 change: 1 addition & 0 deletions server/application/application.proto
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ message ApplicationPodLogsQuery {
required int64 tailLines = 7 [(gogoproto.nullable) = false];
required bool follow = 8 [(gogoproto.nullable) = false];
optional string untilTime = 9;
optional string filter = 10;
}

message LogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export const PodsLogsViewer = (props: {applicationName: string; pod: models.Reso
const [selectedLine, setSelectedLine] = useState(-1);
const bottom = React.useRef<HTMLInputElement>(null);
const [page, setPage] = useState<{number: number; untilTimes: string[]}>({number: 0, untilTimes: []});

interface FilterData {
literal: string;
inverse: boolean;
}
const [filter, setFilter] = useState({inverse: false} as FilterData);

const filterQuery = () => {
return filter.literal && `${filter.inverse ? '!' : ''}${filter.literal}`;
};
return (
<DataLoader load={() => services.viewPreferences.getPreferences()}>
{prefs => (
Expand Down Expand Up @@ -85,6 +95,25 @@ export const PodsLogsViewer = (props: {applicationName: string; pod: models.Reso
}}>
{prefs.appDetails.darkMode ? <i className='fa fa-sun' /> : <i className='fa fa-moon' />}
</div>
<div style={{display: 'flex', marginLeft: 'auto'}}>
rbreeze marked this conversation as resolved.
Show resolved Hide resolved
rbreeze marked this conversation as resolved.
Show resolved Hide resolved
<button
className={`argo-button argo-button--base${filter.inverse ? '' : '-o'}`}
onClick={() => setFilter({...filter, inverse: !filter.inverse})}
style={{marginRight: '10px'}}>
!
</button>
<input
type='text'
placeholder='Filter string'
className='argo-field'
value={filter.literal}
onChange={e => setFilter({...filter, literal: e.target.value})}
style={{padding: 0}}
/>
<button onClick={() => loader.reload()} className='argo-button argo-button--base' style={{width: '150px'}}>
rbreeze marked this conversation as resolved.
Show resolved Hide resolved
FILTER <i className='fa fa-filter' />
</button>
</div>
</div>
<DataLoader
ref={l => (loader = l)}
Expand All @@ -104,7 +133,8 @@ export const PodsLogsViewer = (props: {applicationName: string; pod: models.Reso
container.name,
maxLines * (page.number + 1),
prefs.appDetails.followLogs && page.number === 0,
page.untilTimes[page.untilTimes.length - 1]
page.untilTimes[page.untilTimes.length - 1],
filterQuery()
)
// show only current page lines
.scan((lines, logEntry) => {
Expand Down
5 changes: 3 additions & 2 deletions ui/src/app/shared/services/applications-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export class ApplicationsService {
containerName: string,
tail?: number,
follow?: boolean,
untilTime?: string
untilTime?: string,
filter?: string
): Observable<models.LogEntry> {
if (follow === undefined || follow === null) {
follow = true;
Expand All @@ -177,7 +178,7 @@ export class ApplicationsService {
.loadEventSource(
`/applications/${applicationName}/pods/${podName}/logs?container=${containerName}&follow=${follow}&namespace=${namespace}${tail ? '&tailLines=' + tail : ''}${
untilTime ? '&untilTime=' + untilTime : ''
}`
}${filter ? '&filter=' + filter : ''}`
)
.map(data => JSON.parse(data).result as models.LogEntry);
return new Observable(observer => {
Expand Down