forked from cerc-io/laconic-console
Use wire service logs
This commit is contained in:
parent
02557fb696
commit
ad3ff720ef
@ -22,20 +22,19 @@ system:
|
||||
services:
|
||||
app:
|
||||
prefix: '/app'
|
||||
server: 'http://127.0.0.1:5999'
|
||||
server: 'https://xbox.local'
|
||||
|
||||
wns:
|
||||
server: 'http://127.0.0.1:9473/api'
|
||||
webui: 'http://127.0.0.1:9473/webui'
|
||||
server: 'https://xbox.local/dxos/wns/api'
|
||||
webui: 'https://xbox.local/dxos/wns/webui'
|
||||
|
||||
signal:
|
||||
server: 'http://127.0.0.1:4000'
|
||||
api: 'http://127.0.0.1:4000'
|
||||
server: 'wss://xbox.local/dxos/signal'
|
||||
api: 'https://xbox.local/dxos/signal/'
|
||||
|
||||
ipfs:
|
||||
server: '/ip4/127.0.0.1/tcp/5001'
|
||||
gateway: '/ip4//127.0.0.1:8888/ipfs/'
|
||||
webui: 'http://127.0.0.1:5001/webui'
|
||||
server: 'https://xbox.local/dxos/ipfs/api'
|
||||
gateway: 'https://xbox.local/dxos/ipfs/gateway'
|
||||
|
||||
wellknown:
|
||||
endpoint: 'http://127.0.0.1:9000/.well-known/dxos'
|
||||
endpoint: 'https://xbox.local/.well-known/dxos'
|
||||
|
@ -14,12 +14,13 @@ import Log from '../../../components/Log';
|
||||
const WNSLog = () => {
|
||||
const { config } = useContext(ConsoleContext);
|
||||
const data = useQueryStatusReducer(useQuery(WNS_LOG, { pollInterval: config.api.intervalLog }));
|
||||
console.error(data);
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Log log={data.wns_log.log} />
|
||||
<Log log={JSON.parse(data.wns_log.json)} />
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
#
|
||||
|
||||
query {
|
||||
wns_log @client {
|
||||
wns_log {
|
||||
timestamp
|
||||
log
|
||||
json
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
# NOTE: Set CONFIG_FILE to swap out this config file.
|
||||
#
|
||||
|
||||
# TODO(burdon): Set defaults.
|
||||
|
||||
app:
|
||||
title: 'Console'
|
||||
org': 'DxOS'
|
||||
@ -24,20 +22,19 @@ system:
|
||||
services:
|
||||
app:
|
||||
prefix: '/app'
|
||||
server: 'http://127.0.0.1:5999'
|
||||
server: 'https://xbox.local'
|
||||
|
||||
wns:
|
||||
server: 'https://node1.dxos.network/wns/api'
|
||||
webui: 'https://node1.dxos.network/wns/webui'
|
||||
server: 'https://xbox.local/dxos/wns/api'
|
||||
webui: 'https://xbox.local/dxos/wns/webui'
|
||||
|
||||
signal:
|
||||
server: 'http://127.0.0.1:4000'
|
||||
api: 'http://127.0.0.1:4000'
|
||||
server: 'wss://xbox.local/dxos/signal'
|
||||
api: 'https://xbox.local/dxos/signal/'
|
||||
|
||||
ipfs:
|
||||
server: '/ip4/127.0.0.1/tcp/5001'
|
||||
gateway: '/ip4//127.0.0.1:8888/ipfs/'
|
||||
webui: 'http://127.0.0.1:5001/webui'
|
||||
server: 'https://xbox.local/dxos/ipfs/api'
|
||||
gateway: 'https://xbox.local/dxos/ipfs/gateway'
|
||||
|
||||
wellknown:
|
||||
endpoint: 'http://127.0.0.1:9000/.well-known/dxos'
|
||||
endpoint: 'https://xbox.local/.well-known/dxos'
|
||||
|
@ -8,33 +8,22 @@ type JSONResult {
|
||||
json: String!
|
||||
}
|
||||
|
||||
type Result {
|
||||
timestamp: String!
|
||||
code: Int!
|
||||
}
|
||||
|
||||
type Log {
|
||||
timestamp: String!
|
||||
log: [String]!
|
||||
}
|
||||
|
||||
#
|
||||
# Schema
|
||||
#
|
||||
|
||||
type Mutation {
|
||||
action(command: String!): Result!
|
||||
}
|
||||
|
||||
type Query {
|
||||
system_status: SystemStatus!
|
||||
app_swarm_log: JSONResult!
|
||||
ipfs_log: JSONResult!
|
||||
ipfs_status: JSONResult!
|
||||
ipfs_swarm_log: JSONResult!
|
||||
signal_status: JSONResult!
|
||||
signal_swarm_log: JSONResult!
|
||||
system_status: JSONResult!
|
||||
wns_status: JSONResult!
|
||||
wns_records(type: String): JSONResult!
|
||||
wns_log: Log!
|
||||
wns_log: JSONResult!
|
||||
}
|
||||
|
||||
schema {
|
||||
mutation: Mutation
|
||||
query: Query
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
#
|
||||
# Copyright 2020 DxOS.org
|
||||
#
|
||||
|
||||
type SystemStatus {
|
||||
timestamp: String!
|
||||
json: String!
|
||||
}
|
@ -7,6 +7,7 @@ import defaultsDeep from 'lodash.defaultsdeep';
|
||||
|
||||
import { ipfsResolvers } from './ipfs';
|
||||
import { systemResolvers } from './system';
|
||||
import { logResolvers } from "./log";
|
||||
|
||||
const log = debug('dxos:console:server:resolvers');
|
||||
|
||||
@ -19,14 +20,4 @@ export const resolvers = defaultsDeep({
|
||||
// TODO(burdon): Auth.
|
||||
// https://www.apollographql.com/docs/apollo-server/data/errors/#codes
|
||||
|
||||
Mutation: {
|
||||
action: async (_, { command }) => {
|
||||
log(`WNS action: ${command}`);
|
||||
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
code: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}, ipfsResolvers, systemResolvers);
|
||||
}, ipfsResolvers, systemResolvers, logResolvers);
|
||||
|
65
packages/console-server/src/resolvers/log.js
Normal file
65
packages/console-server/src/resolvers/log.js
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright 2020 DxOS.org
|
||||
//
|
||||
|
||||
import moment from 'moment';
|
||||
import pick from 'lodash.pick';
|
||||
import os from 'os';
|
||||
import si from 'systeminformation';
|
||||
import { spawnSync } from "child_process";
|
||||
|
||||
class LogCache {
|
||||
constructor(maxLines = 500) {
|
||||
// Sets in JS iterate in insertion order.
|
||||
this.buffer = new Set();
|
||||
this.maxLines = maxLines;
|
||||
}
|
||||
|
||||
append(lines) {
|
||||
const added = [];
|
||||
for (const line of lines) {
|
||||
if (!this.buffer.has(line)) {
|
||||
this.buffer.add(line);
|
||||
added.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.buffer.size > this.maxLines) {
|
||||
this.buffer = new Set(Array.from(this.buffer).slice(parseInt(this.maxLines / 2)));
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
}
|
||||
|
||||
const _caches = new Map();
|
||||
const getLogCache = (name) => {
|
||||
let cache = _caches.get(name);
|
||||
if (!cache) {
|
||||
cache = new LogCache();
|
||||
_caches.set(name, cache);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
const getLogs = async (name, lines = 100) => {
|
||||
const command = 'wire';
|
||||
const args = ['service', 'logs', '--lines', lines, name];
|
||||
|
||||
const child = spawnSync(command, args, { encoding: 'utf8' });
|
||||
const logLines = child.stdout.split(/\n/);
|
||||
const cache = getLogCache(name);
|
||||
return cache.append(logLines);
|
||||
};
|
||||
|
||||
export const logResolvers = {
|
||||
Query: {
|
||||
wns_log: async () => {
|
||||
const logs = await getLogs('wns-list');
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
@ -22,7 +22,6 @@ import SYSTEM_STATUS from '@dxos/console-app/src/gql/system_status.graphql';
|
||||
import { resolvers } from '../resolvers';
|
||||
|
||||
import API_SCHEMA from '../gql/api.graphql';
|
||||
import SYSTEM_SCHEMA from '../gql/system.graphql';
|
||||
|
||||
const argv = yargs
|
||||
.option('config', {
|
||||
@ -113,10 +112,7 @@ app.get(publicUrl, (req, res) => {
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs: [
|
||||
API_SCHEMA,
|
||||
SYSTEM_SCHEMA
|
||||
// WNS_EXTENSIONS,
|
||||
// WNS_SCHEMA
|
||||
API_SCHEMA
|
||||
],
|
||||
|
||||
// https://www.apollographql.com/docs/graphql-tools/resolvers
|
||||
|
Loading…
Reference in New Issue
Block a user