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

FP-3066 + FP-3034 #206

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# TBD

- [FP-3066](https://movai.atlassian.net/browse/FP-3066): Fleetboard: Logs of the workers are stored in the manager but the fleetboard is not able to display them correctly
- [FP-3034](https://movai.atlassian.net/browse/FP-3034): Logs - Do not select backend by default

# 1.2.4

- [FP-3073](https://movai.atlassian.net/browse/FP-3073): Frontend says robot offline. Only fixable on browser refresh
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mov-ai/mov-fe-lib-core",
"version": "1.2.4-0",
"version": "1.3.3-0",
"description": "The Mov.AI's core frontend library.",
"keywords": [
"frontend",
Expand Down Expand Up @@ -47,6 +47,8 @@
},
"dependencies": {
"@babel/runtime": "^7.15.4",
"@flatten-js/interval-tree": "^1.1.3",
"@tty-pt/logs": "^0.0.26",
"fast-equals": "^5.0.1",
"js-yaml": "^4.1.0",
"jwt-decode": "^3.1.2",
Expand Down
55 changes: 41 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/api/Features/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (!window.mock) {

const Features = {
get: (key) => features[key],
set: (key) => {
set: (key, value) => {
features[key] = value;
},
enable: (key) => {
Expand All @@ -38,4 +38,6 @@ const Features = {
},
};

globalThis.Features = Features;

export default Features;
85 changes: 85 additions & 0 deletions src/api/Logs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { webSocketOpen } from "../WebSocket";
import Features from "./../Features";
import Rest from "../Rest/Rest";
import { DEFAULT_LEVELS, DEFAULT_SERVICE } from "./../Utils/constants";
import Logs from "@tty-pt/logs";

/**
* Tranform log from the format received from the API to the format
* required to be rendered
* @returns {array} Transformed log
*/
function transform(log, _index, _array, isStream) {
const multiplier = isStream ? 0.000001 : 1000;
const timestamp = multiplier * log.time;
const date = new Date(timestamp);
return {
...log,
timestamp,
time: date.toLocaleTimeString(),
date: date.toLocaleDateString(),
key: log.message + timestamp,
};
}

function streamTransform(msg) {
const original = JSON.parse(msg?.data ?? {});
const { message } = original;

let tags = {};
let realMessage = message;

if (message.charAt(0) === "[") {
const braketParts = message.substring(1).split("] ");

tags = braketParts[0].split("|").reduce((a, item) => {
const [key, value] = item.split(":");
return {
...a,
[key]: value,
};
}, {});

realMessage = braketParts[1];
}

return {
...original,
message: realMessage,
...tags,
};
}

export default class MovaiLogs extends Logs {
static CONSTANTS = {
DEFAULT_LEVELS,
DEFAULT_SERVICE,
};

constructor() {
super({
url: "v1/logs/",
fetch: async (path) => (await Rest.get({ path }))?.data,
transform,

streamUrl: "/ws/logs",
stream: Features.get("logStreaming"),
streamOpen: (streamUrl) =>
webSocketOpen({
path: streamUrl,
params: new URLSearchParams(),
}),
streamTransform,

fields: {
level: { type: "enumeration", default: DEFAULT_LEVELS },
service: { type: "enumeration", default: DEFAULT_SERVICE },
tags: { type: "tags" },
message: { type: "string" },
robot: { type: "enumeration" },
},
});
}
}

globalThis.Logs = MovaiLogs;
Loading
Loading