Skip to content

Commit

Permalink
feat(ui): add some error tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Dec 23, 2022
1 parent b963a82 commit 234e17e
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void report() {
);
this.handleResponse(result);
} catch (HttpClientResponseException t) {
log.warn("Unable to report anonymous usage with body '{}'", t.getResponse().getBody(String.class), t);
log.debug("Unable to report anonymous usage with body '{}'", t.getResponse().getBody(String.class), t);
} catch (Exception t) {
log.error("Unable to handle anonymous usage", t);
}
Expand Down
6 changes: 6 additions & 0 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import Errors from "./components/errors/Errors.vue";
import {mapState} from "vuex";
import Utils from "./utils/utils";
import {pageFromRoute} from "@/utils/eventsRouter";
export default {
name: "App",
Expand Down Expand Up @@ -66,6 +67,11 @@
this.$store.dispatch("plugin/icons")
this.$store.dispatch("misc/loadConfigs")
.then(value => {
this.$store.dispatch("api/events", {
type: "PAGE",
page: pageFromRoute(this.$router.currentRoute.value)
});
this.$store.dispatch("api/loadFeeds", {
version: value.version,
iid: value.uuid,
Expand Down
24 changes: 24 additions & 0 deletions ui/src/components/ErrorToast.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import {ElNotification, ElTable, ElTableColumn} from "element-plus";
import {pageFromRoute} from "@/utils/eventsRouter";
import {h} from "vue"
export default {
Expand Down Expand Up @@ -43,6 +44,29 @@
this.$nextTick(() => {
this.close();
const error = {
type: "ERROR",
error: {
message: this.text,
errors: this.items,
},
page: pageFromRoute(this.$route)
};
if (this.message.response) {
error.error.response = {};
error.error.request = {};
if (this.message.response.status) {
error.error.response.status = this.message.response.status;
}
error.error.request.url = this.message.response.config.url;
error.error.request.method = this.message.response.config.method;
}
this.$store.dispatch("api/events", error);
const children = [
h("span", {innerHTML: this.text})
];
Expand Down
4 changes: 0 additions & 4 deletions ui/src/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
:label="tab.title"
:name="tab.name || 'default'"
:disabled="tab.disabled"
@tab-change="tabChanged"
>
<template #label>
<router-link :to="to(tab)">
Expand Down Expand Up @@ -75,9 +74,6 @@
return {name: this.routeName, params: {...this.$route.params, ...{tab: tab.name}}};
}
},
tabChanged() {
console.log(arguments);
}
},
computed: {
activeTab() {
Expand Down
1 change: 0 additions & 1 deletion ui/src/components/inputs/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@
if (!this.fullHeight) {
editor.onDidContentSizeChange(e => {
console.log()
this.$refs.container.style.height = (e.contentHeight + 7) + "px";
});
}
Expand Down
24 changes: 23 additions & 1 deletion ui/src/stores/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import axios from "axios";

let counter = 0;
const API_URL = "https://api.kestra.io";

export default {
namespaced: true,
Expand All @@ -7,7 +11,7 @@ export default {

actions: {
loadFeeds({commit}, options) {
return this.$http.get("https://api.kestra.io/v1/feeds/latest", {
return axios.get(API_URL + "/v1/feeds/latest", {
params: {
iid: options.iid,
uid: options.uid,
Expand All @@ -18,6 +22,24 @@ export default {

return response.data;
})
},
events({rootGetters}, data) {
let configs = rootGetters["misc/configs"];
let uid = localStorage.getItem("uid");

if (configs === undefined || uid === null || configs["isAnonymousUsageEnabled"] === false) {
return;
}

return axios.post(API_URL + "/v1/reports/events", {
...data,
...{
iid: configs.uuid,
uid: uid,
date: new Date().toISOString(),
counter: counter++,
}
});
}
},
mutations: {
Expand Down
6 changes: 5 additions & 1 deletion ui/src/stores/miscs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ export default {
state.configs = configs
}
},
getters: {}
getters: {
configs(state) {
return state.configs;
}
}
}
2 changes: 2 additions & 0 deletions ui/src/utils/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default (callback, store, router) => {
}, errorResponse => {
if (errorResponse.code && errorResponse.code === "ECONNABORTED") {
store.dispatch("core/showMessage", {
response: errorResponse,
content: errorResponse,
variant: "error"
})
Expand Down Expand Up @@ -114,6 +115,7 @@ export default (callback, store, router) => {

if (errorResponse.response.data) {
store.dispatch("core/showMessage", {
response: errorResponse.response,
content: errorResponse.response.data,
variant: "error"
})
Expand Down
27 changes: 27 additions & 0 deletions ui/src/utils/eventsRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {nextTick} from "vue";

export const pageFromRoute = (route) => {
return {
origin: window.location.origin,
path: route.path,
params: Object.keys(route.params)
.map((key) => ({key: key, value: route.params[key]})),
queries: Object.keys(route.query)
.map((key) => {
return {key: key, values: (route.query[key] instanceof Array ? route.query[key] : [route.query[key]] )}
}),
name: route.name,
hash: route.hash !== "" ? route.hash: undefined,
}
}

export default (app, store, router) => {
router.afterEach((to) => {
nextTick().then(() => {
store.dispatch("api/events", {
type: "PAGE",
page: pageFromRoute(to)
});
});
});
}
2 changes: 2 additions & 0 deletions ui/src/utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Toast from "./toast";
import filters from "./filters";
import ElementPlus from "element-plus";
import createUnsavedChanged from "./unsavedChange";
import createEventsRouter from "./eventsRouter";
import "./global"

export default (app, routes, stores, translations) => {
Expand Down Expand Up @@ -83,6 +84,7 @@ export default (app, routes, stores, translations) => {

// navigation guard
createUnsavedChanged(app, store, router);
createEventsRouter(app, store, router);

return {store, router};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.webserver.controllers;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.kestra.core.repositories.ExecutionRepositoryInterface;
import io.kestra.core.services.InstanceService;
import io.kestra.core.utils.VersionProvider;
Expand Down Expand Up @@ -27,6 +28,9 @@ public class MiscController {
@Inject
InstanceService instanceService;

@io.micronaut.context.annotation.Value("${kestra.anonymous-usage-report.enabled}")
protected Boolean isAnonymousUsageEnabled;

@Get("/ping")
@Hidden
public HttpResponse<?> ping() {
Expand All @@ -42,14 +46,21 @@ public Configuration configuration() {
.uuid(instanceService.fetch())
.version(versionProvider.getVersion())
.isTaskRunEnabled(executionRepository.isTaskRunEnabled())
.isAnonymousUsageEnabled(this.isAnonymousUsageEnabled)
.build();
}

@Value
@Builder
public static class Configuration {
String uuid;

String version;

@JsonInclude
Boolean isTaskRunEnabled;

@JsonInclude
Boolean isAnonymousUsageEnabled;
}
}

0 comments on commit 234e17e

Please sign in to comment.