-
Notifications
You must be signed in to change notification settings - Fork 2
feat: show real time probe logs on the probe page #122
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2ad9273
feat: add probe log tab
PavelKopecky c6b4017
refactor!: add gp api url to nuxt config
PavelKopecky 61d0b81
feat: limit the number of displayed logs
PavelKopecky 1b8e5a3
refactor: improve tab logs code
PavelKopecky 3a63260
fix: handle missing sum data
alexey-yarmosh a37eee3
Merge branch 'master' into gh-26
MartinKolarik 978aab6
fix: add scope, adjust colors
MartinKolarik 83e2794
feat: store active probe detail tab in URL
PavelKopecky eaa29d3
refactor: optimize tab logs with debounced scrolling and props usage
PavelKopecky f7460ff
feat: add LogLoader component with animated loading dots
PavelKopecky cc27a9a
feat: enhance TabLogs with live tail, improved layout, and refined lo…
PavelKopecky e0c06cd
refactor: clear debounce on TabLogs unmount
PavelKopecky b47a8da
refactor: update no probe logs available text
PavelKopecky ebc675f
fix: pluralize and mono
MartinKolarik 8c7cb9c
refactor: adjust dot-pulse animation duration and delay
PavelKopecky 4ee061f
fix: fetch probe logs by probe id and according to redis ids
PavelKopecky 09c537e
refactor: update tab logs live tail checkbox and fix possible log dup…
PavelKopecky a4d42fd
refactor: replace debounce with throttle for scroll handling in TabLo…
PavelKopecky e48c599
fix: adjust styles and improve log handling readability
MartinKolarik 8a5e4f1
fix: improve log display formatting and adjust responsive styles
MartinKolarik 4e01b17
fix: restrict "Logs" tab visibility to admin users
MartinKolarik 0982587
refactor: enable noUncheckedIndexedAccess option (#123)
alexey-yarmosh b021380
feat: update adoption without API response (#124)
alexey-yarmosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| <template> | ||
| <div | ||
| ref="logContainer" | ||
| class="relative flex flex-1 flex-col overflow-y-auto rounded-md border bg-surface-100 p-4 font-mono max-lg:p-2 max-md:gap-4 dark:bg-dark-950" | ||
| @scroll="autoScroll = false" | ||
| @scrollend="onScrollEnd" | ||
| > | ||
| <div | ||
| v-for="(log, index) in logs" | ||
| :key="index" | ||
| :class="{ | ||
| 'text-rose-600 dark:text-red-400': log.level?.toLowerCase() === 'error', | ||
| 'text-orange-600 dark:text-yellow-300': log.level?.toLowerCase() === 'warn', | ||
| 'text-gray-600 dark:text-gray-400': !['error','warn'].includes(log.level?.toLowerCase() || '') | ||
| }" | ||
| > | ||
| <span v-if="log.timestamp">[{{ log.timestamp.toUpperCase() }}] </span> | ||
| <span v-if="log.level">[{{ log.level.toUpperCase() }}] </span> | ||
| <span class="break-words">{{ log.message }}</span> | ||
| </div> | ||
| <span v-if="logs.length === 0" class="inset-0 m-auto text-gray-600 dark:text-gray-400"> | ||
| <span v-if="pending && showLoader"> | ||
| <span class="pi pi-spinner animate-spin text-2xl dark:text-gray-500"/> | ||
| </span> | ||
| <span v-else> | ||
| No logs available. | ||
| </span> | ||
| </span> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { useErrorToast } from '~/composables/useErrorToast'; | ||
| const { isActive } = defineProps({ | ||
| isActive: { | ||
| type: Boolean, | ||
| default: true, | ||
| }, | ||
| }); | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const MAX_LOGS = 5000; | ||
| const config = useRuntimeConfig(); | ||
| const route = useRoute(); | ||
| const probeId = route.params.id as string; | ||
| const refreshInterval = ref<NodeJS.Timeout>(); | ||
| const logContainer = ref<HTMLDivElement | null>(null); | ||
| const autoScroll = ref(true); | ||
| const logs = ref<ProbeLog[]>([]); | ||
| const lastFetched = ref(0); | ||
| const showLoader = ref(true); | ||
| const { data, refresh, pending, error } = await useLazyAsyncData<ProbeLog[]>( | ||
| () => $fetch(`${config.public.gpApiUrl}/v1/probes/${probeId}/logs`, { | ||
| params: { | ||
| since: lastFetched.value, | ||
| }, | ||
| credentials: 'include', | ||
| }), | ||
| { | ||
| default: () => [], | ||
| immediate: false, | ||
| }, | ||
| ); | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| useErrorToast(error); | ||
| const refreshLogs = async () => { | ||
| return refresh().then(() => { | ||
| if (!error.value) { | ||
| lastFetched.value = Date.now(); | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }).catch(() => {}) // errors are displayed via useErrorToast | ||
| .finally(() => { showLoader.value = !isActive; }); // do not show the loader on further refetches | ||
| }; | ||
| const onScrollEnd = () => { | ||
| const scrollHeight = logContainer.value?.scrollHeight ?? 0; | ||
| const scrollTop = logContainer.value?.scrollTop ?? 0; | ||
| const containerHeight = logContainer.value?.clientHeight ?? 0; | ||
| const scrolledTo = scrollTop + containerHeight; | ||
| // if the user scrolled down enough, re-enable autoscroll | ||
| if (scrollHeight - scrolledTo < 30) { | ||
| autoScroll.value = true; | ||
| } | ||
| }; | ||
| const scrollToBottom = () => { | ||
| nextTick(() => { | ||
| if (logContainer.value && autoScroll) { | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logContainer.value.scrollTop = logContainer.value.scrollHeight; | ||
| } | ||
| }); | ||
| }; | ||
| const setRefreshInterval = (timeout = 10000) => { | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (refreshInterval.value) { | ||
| clearInterval(refreshInterval.value); | ||
| } | ||
| refreshInterval.value = setInterval(() => { | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| refreshLogs(); | ||
| }, timeout); | ||
| }; | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // append new logs to the already stored ones | ||
| watch(() => data.value?.length, () => { | ||
| logs.value.push(...data.value); | ||
| if (logs.value.length > MAX_LOGS) { | ||
| logs.value = logs.value.slice(-MAX_LOGS); | ||
| } | ||
| scrollToBottom(); | ||
| }); | ||
PavelKopecky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| watch(() => isActive, (active) => { | ||
| if (active) { | ||
| // fetch data manually on the first tab load | ||
| if (lastFetched.value === 0) { | ||
| refreshLogs(); | ||
| } | ||
| autoScroll.value = true; | ||
| scrollToBottom(); | ||
| setRefreshInterval(); | ||
| } else { | ||
| showLoader.value = true; | ||
| clearInterval(refreshInterval.value); | ||
| } | ||
| }); | ||
| onUnmounted(() => { | ||
| if (refreshInterval.value) { | ||
| clearInterval(refreshInterval.value); | ||
| } | ||
| }); | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.