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

Added federation ping, loopback and dashboard #14007

Merged
merged 7 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
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,
};
},
});
8 changes: 5 additions & 3 deletions app/federation/server/PeerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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 @@ -157,7 +157,7 @@ export class PeerClient {
// Encrypt with the local private key
payload = Federation.privateKey.encryptPrivate(payload);

Federation.peerHTTP.request(peer, 'POST', '/api/v1/federation.events', { payload }, { total: 5, stepSize: 500, stepMultiplier: 10 });
Federation.peerHTTP.request(peer, 'POST', '/api/v1/federation.events', { payload }, eventOptions.retry || { total: 5, stepSize: 500, stepMultiplier: 10 });

FederationEvents.setEventAsFullfilled(e);
} catch (err) {
Expand Down Expand Up @@ -329,7 +329,9 @@ export class PeerClient {
const { peer: { domain: localPeerDomain } } = this;

// Check if room is federated
if (!FederatedRoom.isFederated(localPeerDomain, room, { checkUsingUsers: true })) { return roomOwner; }
if (!FederatedRoom.isFederated(localPeerDomain, room, { checkUsingUsers: true })) {
rodrigok marked this conversation as resolved.
Show resolved Hide resolved
return roomOwner;
}

const owner = Users.findOneById(ownerId);

Expand Down
18 changes: 14 additions & 4 deletions app/federation/server/PeerDNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ export class PeerDNS {

// Try to lookup at the DNS Cache
if (!peer) {
this.updatePeerDNS(domain);
try {
this.updatePeerDNS(domain);

peer = FederationDNSCache.findOneByDomain(domain);
peer = FederationDNSCache.findOneByDomain(domain);
} catch (err) {
this.log(`Could not find peer for domain ${ domain }`);
}
}

return peer;
Expand Down Expand Up @@ -127,7 +131,7 @@ export class PeerDNS {
updatePeerDNS(domain) {
this.log(`updatePeerDNS: ${ domain }`);

let peer;
let peer = null;

try {
peer = this.getPeerUsingDNS(domain);
Expand All @@ -138,7 +142,13 @@ export class PeerDNS {
throw new Error(`Error trying to fetch SRV DNS entries for ${ domain }`);
}

peer = this.getPeerUsingHub(domain);
try {
peer = this.getPeerUsingHub(domain);
} catch (err) {
throw new Error(
rodrigok marked this conversation as resolved.
Show resolved Hide resolved
`Could not find a peer with domain ${ domain } using the hub`
);
}
}

this.updateDNSCache.call(this, peer);
Expand Down
Loading