Skip to content

Commit

Permalink
Create separate logger per job
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Sep 24, 2023
1 parent e99613b commit 870a6e7
Show file tree
Hide file tree
Showing 20 changed files with 487 additions and 58 deletions.
8 changes: 2 additions & 6 deletions apps/ui/src/components/ChangesViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<td>
{{ job.finishedStr }}
({{ job.durationStr }})
<button class="btn float-end" @click="showLogs(job)">Logs</button>
<a class="btn float-end" :href="'#drive_logs:job-' + job.id" @click.prevent="showLogs(job)">Logs</a>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -177,11 +177,7 @@ export default {
}
},
showLogs(job) {
this.$emit('showLogs', {
from: job.started,
until: job.finished
});
this.setActiveTab('drive_logs');
this.setActiveTab('drive_logs:job-' + job.id);
}
}
};
Expand Down
143 changes: 143 additions & 0 deletions apps/ui/src/components/JobLogsViewer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<template>
<div class="x-container mainbar__content-height">
<StatusToolBar :active-tab="activeTab">
</StatusToolBar>

<div class="btn-toolbar">
<div class="flex-grow-1"></div>
<button class="btn btn-sm" @click="errorsOnly = !errorsOnly">{{ errorsOnly ? 'Show all logs' : 'Show errors only' }}</button>
</div>

<pre class="bg-dark text-white log-viewer overflow-auto"
><div v-for="(item, idx) of logsFiltered" :key="idx" :class="{'text-danger': 'error' === item.level, 'text-warning': 'warn' === item.level}"
><span>[{{dateStr(item.timestamp)}}]</span
> <span v-html="getLink(item.filename)"></span
> <span v-html="highLight(item.message)"></span
></div>
</pre>
</div>
</template>

<script>
import {UtilsMixin} from './UtilsMixin.ts';
import StatusToolBar from './StatusToolBar.vue';
import {Prism} from './prismFix';
export default {
mixins: [UtilsMixin],
components: {StatusToolBar},
props: {
activeTab: {
type: String
},
jobId: {
type: String
},
contentDir: {
type: String
}
},
data() {
return {
errorsOnly: false,
logs: []
};
},
computed: {
absPath() {
return '/drive/' + this.driveId + this.contentDir;
},
logsFiltered() {
let retVal = this.logs;
if (this.errorsOnly) {
retVal = retVal.filter(item => ['error', 'warn'].includes(item.level));
}
return retVal;
}
},
methods: {
async fetch() {
if (!this.jobId || !this.jobId.startsWith('job-')) {
return;
}
const jobId = this.jobId.substring('job-'.length);
const response = await this.authenticatedClient.fetchApi(`/api/logs/${this.driveId}?order=asc&jobId=` + (jobId));
const logs = await response.json();
if (logs.length === 0) {
return;
}
this.logs = logs;
if (logs.length > 0) {
this.handleScroll();
}
},
handleScroll() {
const scroller = document.querySelector('.mainbar__content-height > pre');
if (scroller) {
const oldScrollTop = scroller.scrollHeight - scroller.offsetHeight - 10;
if (scroller.scrollTop < oldScrollTop) {
this.$nextTick(() => {
const scroller = document.querySelector('.mainbar__content-height > pre');
if (scroller) {
scroller.scrollTop = scroller.scrollHeight - scroller.offsetHeight;
}
});
}
}
this.$nextTick(() => {
this.rewriteLinks();
});
},
getLink(fileName) {
if (!fileName) {
return '';
}
const [path, line] = fileName.split(':');
const branch = window.location.hostname === 'wikigdrive.com' ? 'master' : 'develop';
const url = `https://github.com/mieweb/wikiGDrive/blob/${branch}/${path}#L${line}`;
let baseName = path.split('/').pop();
return `<a target="github" href="${url}">${baseName}</a>`;
},
dateStr(v) {
if (!v) {
return '';
}
return new Date(v).toISOString();
},
highLight(str) {
return Prism.highlight(str, Prism.languages.markdown, 'markdown');
},
rewriteLinks() {
const links = this.$el.querySelectorAll('a[data-to-rewrite]');
for (const link of links) {
const href = link.getAttribute('href');
if (href.endsWith('.md')) {
link.setAttribute('href', this.absPath + '/' + href + '#markdown');
link.addEventListener('click', event => {
event.preventDefault();
this.$router.push(link.getAttribute('href'));
});
} else
if (href.endsWith('.svg')) {
link.setAttribute('href', this.absPath + '/' + href);
link.addEventListener('click', event => {
event.preventDefault();
this.$router.push(link.getAttribute('href'));
});
}
link.removeAttribute('data-to-rewrite');
}
}
},
async mounted() {
await this.fetch();
this.handleScroll();
// Prism.highlightElement(this.$refs.code);
}
};
</script>
2 changes: 0 additions & 2 deletions apps/ui/src/components/UiMixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const DEFAULT_TAB = 'html';

export const UiMixin = {
data() {
return {
Expand Down
6 changes: 6 additions & 0 deletions apps/ui/src/components/UtilsMixin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const DEFAULT_TAB = 'html';

export async function disableElement(event, handler) {
const origAttr = event.target.getAttribute('disabled');
if ('disabled' === origAttr) {
Expand Down Expand Up @@ -111,6 +113,10 @@ export const UtilsMixin = {
}
},
methods: {
getActiveTab() {
const parts = (this.$route.hash.replace(/^#/, '') || DEFAULT_TAB).split(':');
return parts;
},
setActiveTab(tab, selectedFilePath) {
if (this.isAddon) {
if (this.fullDrivePath) {
Expand Down
23 changes: 17 additions & 6 deletions apps/ui/src/pages/FolderView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
<GitSettings v-if="activeTab === 'git_settings'" :active-tab="activeTab" :tree-empty="treeEmpty" />

<DriveTools v-if="activeTab === 'drive_tools'" :folderPath="folderPath" :selectedFile="selectedFile" :selected-folder="selectedFolder" :active-tab="activeTab" />
<LogsViewer v-if="activeTab === 'drive_logs'" :contentDir="contentDir" :active-tab="activeTab" v-model="logsState" />

<div v-if="activeTab === 'drive_logs'">
<JobLogsViewer v-if="activeTabParams[0]" contentDir="contentDir" :active-tab="activeTab" :jobId="activeTabParams[0]" />
<LogsViewer v-else :contentDir="contentDir" :active-tab="activeTab" v-model="logsState" />
</div>

<ZipkinViewer v-if="activeTab === 'performance'" :active-tab="activeTab" />
<DangerSettings v-if="activeTab === 'drive_danger'" :activeTab="activeTab" />
<UserSettings v-if="activeTab === 'drive_config' || activeTab === 'drive_config_git'" :activeTab="activeTab" />
Expand Down Expand Up @@ -95,8 +100,8 @@
</template>
<script lang="ts">
import BaseLayout from '../layout/BaseLayout.vue';
import {DEFAULT_TAB, UiMixin} from '../components/UiMixin.ts';
import {UtilsMixin} from '../components/UtilsMixin.ts';
import {UiMixin} from '../components/UiMixin.ts';
import {DEFAULT_TAB, UtilsMixin} from '../components/UtilsMixin.ts';
import FilesTree from '../components/FilesTree.vue';
import NotRegistered from './NotRegistered.vue';
import FilePreview from '../components/FilePreview.vue';
Expand All @@ -106,6 +111,7 @@ import FileEditor from '../components/FileEditor.vue';
import NavTabs from '../components/NavTabs.vue';
import NavSearch from '../components/NavSearch.vue';
import LogsViewer from '../components/LogsViewer.vue';
import JobLogsViewer from '../components/JobLogsViewer.vue';
import ZipkinViewer from '../components/ZipkinViewer.vue';
import ChangesViewer from '../components/ChangesViewer.vue';
import UserSettings from '../components/UserSettings.vue';
Expand Down Expand Up @@ -134,6 +140,7 @@ export default {
IframePreview,
FileEditor,
LogsViewer,
JobLogsViewer,
ZipkinViewer,
ChangesViewer,
UserSettings,
Expand All @@ -150,8 +157,12 @@ export default {
folderPath: '',
contentDir: '',
activeTab: DEFAULT_TAB,
activeTabParams: [],
files: [],
selectedFile: {},
selectedFile: {
id: null,
mimeType: ''
},
selectedFolder: {},
driveEmpty: false,
treeEmpty: false,
Expand Down Expand Up @@ -193,11 +204,11 @@ export default {
watch: {
async $route() {
await this.fetch();
this.activeTab = this.$route.hash.replace(/^#/, '') || DEFAULT_TAB;
[this.activeTab, ...this.activeTabParams] = this.getActiveTab();
}
},
mounted() {
this.activeTab = this.$route.hash.replace(/^#/, '') || DEFAULT_TAB;
[this.activeTab, ...this.activeTabParams] = this.getActiveTab();
},
methods: {
async fetchFolder(driveId, filePath) {
Expand Down
9 changes: 5 additions & 4 deletions apps/ui/src/pages/GDocsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
<script lang="js">
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import {DEFAULT_TAB, UiMixin} from '../components/UiMixin.ts';
import {disableElement, UtilsMixin} from '../components/UtilsMixin.ts';
import {UiMixin} from '../components/UiMixin.ts';
import {DEFAULT_TAB, disableElement, UtilsMixin} from '../components/UtilsMixin.ts';
import {GitMixin} from '../components/GitMixin.ts';
import BaseLayout from '../layout/BaseLayout.vue';
import NotRegistered from './NotRegistered.vue';
Expand Down Expand Up @@ -237,6 +237,7 @@ export default {
untransformed: null,
commitMsg: '',
activeTab: DEFAULT_TAB,
activeTabParams: [],
folderPath: '',
contentDir: '',
selectedFile: {},
Expand Down Expand Up @@ -287,14 +288,14 @@ export default {
watch: {
async $route() {
await this.fetch();
this.activeTab = this.$route.hash.replace(/^#/, '') || DEFAULT_TAB;
[this.activeTab, ...this.activeTabParams] = this.getActiveTab();
},
async active_jobs() {
await this.fetch();
}
},
mounted() {
this.activeTab = this.$route.hash.replace(/^#/, '') || DEFAULT_TAB;
[this.activeTab, ...this.activeTabParams] = this.getActiveTab();
},
methods: {
async commitSinglePush(event) {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/action/ActionRunnerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ActionRunnerContainer extends Container {

async init(engine: ContainerEngine): Promise<void> {
await super.init(engine);
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name });
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name, jobId: this.params.jobId });
}

async convertActionYaml(actionYaml: string): Promise<ActionDefinition[]> {
Expand Down
4 changes: 3 additions & 1 deletion src/containers/changes/WatchChangesContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {fileURLToPath} from 'url';
import {FolderRegistryContainer} from '../folder_registry/FolderRegistryContainer';
import {GoogleFile} from '../../model/GoogleFile';
import {GoogleTreeProcessor} from '../google_folder/GoogleTreeProcessor';
import {JobManagerContainer} from '../job/JobManagerContainer';
import {initJob, JobManagerContainer} from '../job/JobManagerContainer';
import {UserConfigService} from '../google_folder/UserConfigService';
import {type FileId} from '../../model/model';
import {TelemetryClass, TelemetryMethod, TelemetryMethodDisable} from '../../telemetry';
Expand Down Expand Up @@ -93,11 +93,13 @@ export class WatchChangesContainer extends Container {

const jobManagerContainer = <JobManagerContainer>this.engine.getContainer('job_manager');
await jobManagerContainer.schedule(driveId, {
...initJob(),
type: 'sync',
payload: fileIdsString,
title: 'Syncing file: ' + fileIdsString
});
await jobManagerContainer.schedule(driveId, {
...initJob(),
type: 'transform',
title: 'Transform markdown'
});
Expand Down
2 changes: 1 addition & 1 deletion src/containers/google_folder/GoogleFolderContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class GoogleFolderContainer extends Container {

async init(engine: ContainerEngine): Promise<void> {
await super.init(engine);
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name });
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name, jobId: this.params.jobId });
const googleApiContainer: GoogleApiContainer = <GoogleApiContainer>this.engine.getContainer('google_api');
this.googleDriveService = new GoogleDriveService(this.logger, googleApiContainer.getQuotaLimiter());
this.auth = googleApiContainer.getAuth();
Expand Down
2 changes: 1 addition & 1 deletion src/containers/google_folder/UploadContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UploadContainer extends Container {

async init(engine: ContainerEngine): Promise<void> {
await super.init(engine);
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name });
this.logger = engine.logger.child({ filename: __filename, driveId: this.params.name, jobId: this.params.jobId });
this.googleDriveService = new GoogleDriveService(this.logger, null);
// this.auth = googleApiContainer.getAuth();
}
Expand Down
Loading

0 comments on commit 870a6e7

Please sign in to comment.