Skip to content

Commit

Permalink
Added new ping system, also a federation dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
alansikora committed Apr 22, 2019
1 parent e6c8816 commit 28e9abf
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 95 deletions.
141 changes: 141 additions & 0 deletions app/federation/client/admin/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
.status {
flex: 0 0 auto;

width: 6px;
height: 6px;
margin: 0 7px;

border-radius: 50%;
}

.status.stable {
background-color: #2de0a5;
}

.status.unstable {
background-color: #ffd21f;
}

.status.failing {
background-color: #f5455c;
}

.frame {
display: flex;
flex-direction: row;
}

.group {
display: flex;
flex-direction: row;
flex: 100%;

max-width: 100%;
margin: 10px;

border-width: 1px;
align-items: center;
justify-content: center;
}

.group.left {
justify-content: flex-start;
}

.group.wrap {
flex-wrap: wrap;
}

.overview-column {
flex: 100%;

min-height: 20px;
margin: 15px 0;
}

.overview-column.small {
max-width: 20%;
}

.group .overview-column:not(:last-child) {
border-right: 1px solid #e9e9e9;
}

.group .overview-column:nth-child(5n) {
border-right: 0;
}

.overview-pill {
display: flex;

width: 100%;
padding: 0 10px;

user-select: text;
text-align: center;
align-items: center;
}

.overview-item {
width: 100%;

user-select: text;
text-align: center;
}

.overview-item > .title {
display: inline-block;

margin-top: 8px;

text-transform: uppercase;

color: #9ea2a8;

font-size: 0.875rem;
font-weight: 300;
}

.overview-item > .value {
display: inline-block;

width: 100%;

text-transform: capitalize;

color: #383838;

font-size: 1.75rem;
font-weight: 400;
line-height: 1;
}

@media screen and (max-width: 925px) {
.overview-item > .title {
font-size: 0.5rem;
}

.overview-item > .value {
font-size: 1rem;
}
}

@media screen and (max-width: 800px) {
.overview-item > .title {
font-size: 0.875rem;
}

.overview-item > .value {
font-size: 1.75rem;
}
}

@media screen and (max-width: 600px) {
.overview-item > .title {
font-size: 0.5rem;
}

.overview-item > .value {
font-size: 1rem;
}
}
33 changes: 33 additions & 0 deletions app/federation/client/admin/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template name="dashboard">
<div class="main-content-flex">
<section class="page-container page-list flex-tab-main-content">
{{> header sectionName="Federation_Dashboard"}}
<div class="content">
<div class="section">
<div class="section-content">
<div class="group border-component-color">
{{#each federationOverviewData}}
<div class="overview-column">
<div class="overview-item">
<span class="value">{{value}}</span>
<span class="title">{{_ title}}</span>
</div>
</div>
{{/each}}
</div>
<div class="group left wrap border-component-color">
{{#each federationPeerStatuses}}
<div class="overview-column small">
<div class="overview-pill" title="{{status}} - {{statusAt}}">
<div class="status {{status}}"></div>
<span class="title">{{peer}}</span>
</div>
</div>
{{/each}}
</div>
</div>
</div>
</div>
</section>
</div>
</template>
92 changes: 92 additions & 0 deletions app/federation/client/admin/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { AdminBox } from '../../../ui-utils';
import { hasRole } from '../../../authorization';

import './dashboard.html';
import './dashboard.css';

// Template controller
let templateInstance; // current template instance/context

// Methods
const updateOverviewData = () => {
Meteor.call('federation:getOverviewData', (error, result) => {
if (error) {
console.log(error);

return;
// return handleError(error);
}

const { data } = result;

templateInstance.federationOverviewData.set(data);
});
};

const updatePeerStatuses = () => {
Meteor.call('federation:getPeerStatuses', (error, result) => {
if (error) {
console.log(error);

return;
// return handleError(error);
}

const { data } = result;

templateInstance.federationPeerStatuses.set(data);
});
};

const updateData = () => {
updateOverviewData();
updatePeerStatuses();
};

Template.dashboard.helpers({
federationOverviewData() {
return templateInstance.federationOverviewData.get();
},
federationPeerStatuses() {
return templateInstance.federationPeerStatuses.get();
},
});

// Events
Template.dashboard.onCreated(function() {
templateInstance = Template.instance();

this.federationOverviewData = new ReactiveVar();
this.federationPeerStatuses = new ReactiveVar();
});

Template.dashboard.onRendered(() => {
Tracker.autorun(updateData);

setInterval(updateData, 10000);
});

// Route setup

FlowRouter.route('/admin/federation-dashboard', {
name: 'federation-dashboard',
action() {
BlazeLayout.render('main', { center: 'dashboard', old: true });
},
});

AdminBox.addOption({
icon: 'discover',
href: 'admin/federation-dashboard',
i18nLabel: 'Federation Dashboard',
permissionGranted() {
return hasRole(Meteor.userId(), 'admin');
},
});
25 changes: 2 additions & 23 deletions app/federation/client/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
import { MessageTypes } from '../../ui-utils/client';

// Register message types
MessageTypes.registerType({
id: 'rejected-message-by-peer',
system: true,
message: 'This_message_was_rejected_by__peer__peer',
data(message) {
return {
peer: message.peer,
};
},
});
MessageTypes.registerType({
id: 'peer-does-not-exist',
system: true,
message: 'The_peer__peer__does_not_exist',
data(message) {
return {
peer: message.peer,
};
},
});
import './messageTypes';
import './admin/dashboard';
23 changes: 23 additions & 0 deletions app/federation/client/messageTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MessageTypes } from '../../ui-utils/client';

// Register message types
MessageTypes.registerType({
id: 'rejected-message-by-peer',
system: true,
message: 'This_message_was_rejected_by__peer__peer',
data(message) {
return {
peer: message.peer,
};
},
});
MessageTypes.registerType({
id: 'peer-does-not-exist',
system: true,
message: 'The_peer__peer__does_not_exist',
data(message) {
return {
peer: message.peer,
};
},
});
4 changes: 2 additions & 2 deletions app/federation/server/PeerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class PeerClient {
propagateEvent(e) {
this.log(`propagateEvent: ${ e.t }`);

const { peer: domain } = e;
const { peer: domain, options: eventOptions } = e;

const peer = Federation.peerDNS.searchPeer(domain);

Expand All @@ -249,7 +249,7 @@ export class PeerClient {
'POST',
'/api/v1/federation.events',
{ payload },
{ total: 5, stepSize: 500, stepMultiplier: 10 }
eventOptions.retry || { total: 5, stepSize: 500, stepMultiplier: 10 }
);

FederationEvents.setEventAsFullfilled(e);
Expand Down
38 changes: 19 additions & 19 deletions app/federation/server/PeerPinger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ import { ping } from './methods/ping';
import moment from 'moment';

export class PeerPinger {
constructor() {
this.config = {
pingInterval: 5000
};
constructor() {
this.config = {
pingInterval: 5000,
};

this.peers = [];
}
this.peers = [];
}

log(message) {
logger.pinger.info(message);
}
log(message) {
logger.pinger.info(message);
}

start() {
this.pingAllPeers();
}
start() {
this.pingAllPeers();
}

pingAllPeers() {
const lastSeenAt = moment().subtract(10, 'm').toDate();
pingAllPeers() {
const lastSeenAt = moment().subtract(10, 'm').toDate();

const peers = FederationPeers.find({ $or: [{ last_seen_at: null }, { last_seen_at: { $lte: lastSeenAt } }] }).fetch();
const peers = FederationPeers.find({ $or: [{ last_seen_at: null }, { last_seen_at: { $lte: lastSeenAt } }] }).fetch();

const pingResults = ping(peers.map(p => p.peer));
const pingResults = ping(peers.map((p) => p.peer));

FederationPeers.updateStatuses(pingResults);
FederationPeers.updateStatuses(pingResults);

Meteor.setTimeout(this.pingAllPeers.bind(this), this.config.pingInterval);
}
Meteor.setTimeout(this.pingAllPeers.bind(this), this.config.pingInterval);
}
}
Loading

0 comments on commit 28e9abf

Please sign in to comment.