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:
|
services:
|
||||||
app:
|
app:
|
||||||
prefix: '/app'
|
prefix: '/app'
|
||||||
server: 'http://127.0.0.1:5999'
|
server: 'https://xbox.local'
|
||||||
|
|
||||||
wns:
|
wns:
|
||||||
server: 'http://127.0.0.1:9473/api'
|
server: 'https://xbox.local/dxos/wns/api'
|
||||||
webui: 'http://127.0.0.1:9473/webui'
|
webui: 'https://xbox.local/dxos/wns/webui'
|
||||||
|
|
||||||
signal:
|
signal:
|
||||||
server: 'http://127.0.0.1:4000'
|
server: 'wss://xbox.local/dxos/signal'
|
||||||
api: 'http://127.0.0.1:4000'
|
api: 'https://xbox.local/dxos/signal/'
|
||||||
|
|
||||||
ipfs:
|
ipfs:
|
||||||
server: '/ip4/127.0.0.1/tcp/5001'
|
server: 'https://xbox.local/dxos/ipfs/api'
|
||||||
gateway: '/ip4//127.0.0.1:8888/ipfs/'
|
gateway: 'https://xbox.local/dxos/ipfs/gateway'
|
||||||
webui: 'http://127.0.0.1:5001/webui'
|
|
||||||
|
|
||||||
wellknown:
|
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 WNSLog = () => {
|
||||||
const { config } = useContext(ConsoleContext);
|
const { config } = useContext(ConsoleContext);
|
||||||
const data = useQueryStatusReducer(useQuery(WNS_LOG, { pollInterval: config.api.intervalLog }));
|
const data = useQueryStatusReducer(useQuery(WNS_LOG, { pollInterval: config.api.intervalLog }));
|
||||||
|
console.error(data);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Log log={data.wns_log.log} />
|
<Log log={JSON.parse(data.wns_log.json)} />
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
query {
|
query {
|
||||||
wns_log @client {
|
wns_log {
|
||||||
timestamp
|
timestamp
|
||||||
log
|
json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
# NOTE: Set CONFIG_FILE to swap out this config file.
|
# NOTE: Set CONFIG_FILE to swap out this config file.
|
||||||
#
|
#
|
||||||
|
|
||||||
# TODO(burdon): Set defaults.
|
|
||||||
|
|
||||||
app:
|
app:
|
||||||
title: 'Console'
|
title: 'Console'
|
||||||
org': 'DxOS'
|
org': 'DxOS'
|
||||||
@ -24,20 +22,19 @@ system:
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
prefix: '/app'
|
prefix: '/app'
|
||||||
server: 'http://127.0.0.1:5999'
|
server: 'https://xbox.local'
|
||||||
|
|
||||||
wns:
|
wns:
|
||||||
server: 'https://node1.dxos.network/wns/api'
|
server: 'https://xbox.local/dxos/wns/api'
|
||||||
webui: 'https://node1.dxos.network/wns/webui'
|
webui: 'https://xbox.local/dxos/wns/webui'
|
||||||
|
|
||||||
signal:
|
signal:
|
||||||
server: 'http://127.0.0.1:4000'
|
server: 'wss://xbox.local/dxos/signal'
|
||||||
api: 'http://127.0.0.1:4000'
|
api: 'https://xbox.local/dxos/signal/'
|
||||||
|
|
||||||
ipfs:
|
ipfs:
|
||||||
server: '/ip4/127.0.0.1/tcp/5001'
|
server: 'https://xbox.local/dxos/ipfs/api'
|
||||||
gateway: '/ip4//127.0.0.1:8888/ipfs/'
|
gateway: 'https://xbox.local/dxos/ipfs/gateway'
|
||||||
webui: 'http://127.0.0.1:5001/webui'
|
|
||||||
|
|
||||||
wellknown:
|
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!
|
json: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result {
|
|
||||||
timestamp: String!
|
|
||||||
code: Int!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Log {
|
|
||||||
timestamp: String!
|
|
||||||
log: [String]!
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Schema
|
# Schema
|
||||||
#
|
#
|
||||||
|
|
||||||
type Mutation {
|
|
||||||
action(command: String!): Result!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
system_status: SystemStatus!
|
app_swarm_log: JSONResult!
|
||||||
|
ipfs_log: JSONResult!
|
||||||
ipfs_status: JSONResult!
|
ipfs_status: JSONResult!
|
||||||
|
ipfs_swarm_log: JSONResult!
|
||||||
|
signal_status: JSONResult!
|
||||||
|
signal_swarm_log: JSONResult!
|
||||||
|
system_status: JSONResult!
|
||||||
wns_status: JSONResult!
|
wns_status: JSONResult!
|
||||||
wns_records(type: String): JSONResult!
|
wns_log: JSONResult!
|
||||||
wns_log: Log!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
mutation: Mutation
|
|
||||||
query: Query
|
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 { ipfsResolvers } from './ipfs';
|
||||||
import { systemResolvers } from './system';
|
import { systemResolvers } from './system';
|
||||||
|
import { logResolvers } from "./log";
|
||||||
|
|
||||||
const log = debug('dxos:console:server:resolvers');
|
const log = debug('dxos:console:server:resolvers');
|
||||||
|
|
||||||
@ -19,14 +20,4 @@ export const resolvers = defaultsDeep({
|
|||||||
// TODO(burdon): Auth.
|
// TODO(burdon): Auth.
|
||||||
// https://www.apollographql.com/docs/apollo-server/data/errors/#codes
|
// https://www.apollographql.com/docs/apollo-server/data/errors/#codes
|
||||||
|
|
||||||
Mutation: {
|
}, ipfsResolvers, systemResolvers, logResolvers);
|
||||||
action: async (_, { command }) => {
|
|
||||||
log(`WNS action: ${command}`);
|
|
||||||
|
|
||||||
return {
|
|
||||||
timestamp: new Date().toUTCString(),
|
|
||||||
code: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, ipfsResolvers, systemResolvers);
|
|
||||||
|
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 { resolvers } from '../resolvers';
|
||||||
|
|
||||||
import API_SCHEMA from '../gql/api.graphql';
|
import API_SCHEMA from '../gql/api.graphql';
|
||||||
import SYSTEM_SCHEMA from '../gql/system.graphql';
|
|
||||||
|
|
||||||
const argv = yargs
|
const argv = yargs
|
||||||
.option('config', {
|
.option('config', {
|
||||||
@ -113,10 +112,7 @@ app.get(publicUrl, (req, res) => {
|
|||||||
|
|
||||||
const server = new ApolloServer({
|
const server = new ApolloServer({
|
||||||
typeDefs: [
|
typeDefs: [
|
||||||
API_SCHEMA,
|
API_SCHEMA
|
||||||
SYSTEM_SCHEMA
|
|
||||||
// WNS_EXTENSIONS,
|
|
||||||
// WNS_SCHEMA
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// https://www.apollographql.com/docs/graphql-tools/resolvers
|
// https://www.apollographql.com/docs/graphql-tools/resolvers
|
||||||
|
Loading…
Reference in New Issue
Block a user