mirror of https://github.com/calzoneman/sync.git
Minor fixes, logging, metrics
This commit is contained in:
parent
13585a5e6a
commit
24a13c12cf
|
@ -3,7 +3,7 @@ var Flags = require("../flags");
|
||||||
var util = require("../utilities");
|
var util = require("../utilities");
|
||||||
var InfoGetter = require("../get-info");
|
var InfoGetter = require("../get-info");
|
||||||
var db = require("../database");
|
var db = require("../database");
|
||||||
var Media = require("../media");
|
import { Counter, Summary } from 'prom-client';
|
||||||
const LOGGER = require('@calzoneman/jsli')('channel/library');
|
const LOGGER = require('@calzoneman/jsli')('channel/library');
|
||||||
|
|
||||||
const TYPE_UNCACHE = {
|
const TYPE_UNCACHE = {
|
||||||
|
@ -45,17 +45,6 @@ LibraryModule.prototype.cacheMediaList = function (list) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LibraryModule.prototype.getItem = function (id, cb) {
|
|
||||||
db.channels.getLibraryItem(this.channel.name, id, function (err, row) {
|
|
||||||
if (err) {
|
|
||||||
cb(err, null);
|
|
||||||
} else {
|
|
||||||
var meta = JSON.parse(row.meta || "{}");
|
|
||||||
cb(null, new Media(row.id, row.title, row.seconds, row.type, meta));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
LibraryModule.prototype.handleUncache = function (user, data) {
|
LibraryModule.prototype.handleUncache = function (user, data) {
|
||||||
if (!this.channel.is(Flags.C_REGISTERED)) {
|
if (!this.channel.is(Flags.C_REGISTERED)) {
|
||||||
return;
|
return;
|
||||||
|
@ -81,11 +70,24 @@ LibraryModule.prototype.handleUncache = function (user, data) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const librarySearchQueryCount = new Counter({
|
||||||
|
name: 'cytube_library_search_query_count',
|
||||||
|
help: 'Counter for number of channel library searches',
|
||||||
|
labelNames: ['source']
|
||||||
|
});
|
||||||
|
const librarySearchResultSize = new Summary({
|
||||||
|
name: 'cytube_library_search_results_size',
|
||||||
|
help: 'Summary for number of channel library results returned',
|
||||||
|
labelNames: ['source']
|
||||||
|
});
|
||||||
LibraryModule.prototype.handleSearchMedia = function (user, data) {
|
LibraryModule.prototype.handleSearchMedia = function (user, data) {
|
||||||
var query = data.query.substring(0, 100);
|
var query = data.query.substring(0, 100);
|
||||||
var searchYT = function () {
|
var searchYT = function () {
|
||||||
|
librarySearchQueryCount.labels('yt').inc(1, new Date());
|
||||||
InfoGetter.Getters.ytSearch(query, function (e, vids) {
|
InfoGetter.Getters.ytSearch(query, function (e, vids) {
|
||||||
if (!e) {
|
if (!e) {
|
||||||
|
librarySearchResultSize.labels('yt')
|
||||||
|
.observe(vids.length, new Date());
|
||||||
user.socket.emit("searchResults", {
|
user.socket.emit("searchResults", {
|
||||||
source: "yt",
|
source: "yt",
|
||||||
results: vids
|
results: vids
|
||||||
|
@ -98,11 +100,16 @@ LibraryModule.prototype.handleSearchMedia = function (user, data) {
|
||||||
!this.channel.modules.permissions.canSeePlaylist(user)) {
|
!this.channel.modules.permissions.canSeePlaylist(user)) {
|
||||||
searchYT();
|
searchYT();
|
||||||
} else {
|
} else {
|
||||||
|
librarySearchQueryCount.labels('library').inc(1, new Date());
|
||||||
|
|
||||||
db.channels.searchLibrary(this.channel.name, query, function (err, res) {
|
db.channels.searchLibrary(this.channel.name, query, function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res = [];
|
res = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
librarySearchResultSize.labels('library')
|
||||||
|
.observe(res.length, new Date());
|
||||||
|
|
||||||
if (res.length === 0) {
|
if (res.length === 0) {
|
||||||
return searchYT();
|
return searchYT();
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,10 +394,6 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
|
||||||
|
|
||||||
var id = data.id;
|
var id = data.id;
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
if (type === "lib") {
|
|
||||||
LOGGER.warn("Outdated client: IP %s emitting queue with type=lib",
|
|
||||||
user.realip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.pos !== "next" && data.pos !== "end") {
|
if (data.pos !== "next" && data.pos !== "end") {
|
||||||
return;
|
return;
|
||||||
|
@ -522,42 +518,18 @@ PlaylistModule.prototype.queueStandard = function (user, data) {
|
||||||
this.channel.refCounter.ref("PlaylistModule::queueStandard");
|
this.channel.refCounter.ref("PlaylistModule::queueStandard");
|
||||||
counters.add("playlist:queue:count", 1);
|
counters.add("playlist:queue:count", 1);
|
||||||
this.semaphore.queue(function (lock) {
|
this.semaphore.queue(function (lock) {
|
||||||
var lib = self.channel.modules.library;
|
InfoGetter.getMedia(data.id, data.type, function (err, media) {
|
||||||
if (lib && self.channel.is(Flags.C_REGISTERED) && !util.isLive(data.type)) {
|
if (err) {
|
||||||
// TODO: remove this check entirely once metrics are collected.
|
error(XSS.sanitizeText(String(err)));
|
||||||
lib.getItem(data.id, function (err, item) {
|
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
||||||
if (err && err !== "Item not in library") {
|
return lock.release();
|
||||||
LOGGER.error("Failed to query for library item: %s", String(err));
|
}
|
||||||
} else if (err === "Item not in library") {
|
|
||||||
counters.add("playlist:queue:library:miss", 1);
|
|
||||||
} else {
|
|
||||||
// temp hack until all clients are updated.
|
|
||||||
// previously, library search results would queue with
|
|
||||||
// type "lib"; this has now been changed.
|
|
||||||
data.type = item.type;
|
|
||||||
counters.add("playlist:queue:library:hit", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleLookup();
|
self._addItem(media, data, user, function () {
|
||||||
|
lock.release();
|
||||||
|
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
handleLookup();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleLookup() {
|
|
||||||
InfoGetter.getMedia(data.id, data.type, function (err, media) {
|
|
||||||
if (err) {
|
|
||||||
error(XSS.sanitizeText(String(err)));
|
|
||||||
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
|
||||||
return lock.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
self._addItem(media, data, user, function () {
|
|
||||||
lock.release();
|
|
||||||
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,15 @@ class IOServer {
|
||||||
|
|
||||||
LOGGER.info('Accepted socket from %s', socket.context.ipAddress);
|
LOGGER.info('Accepted socket from %s', socket.context.ipAddress);
|
||||||
counters.add('socket.io:accept', 1);
|
counters.add('socket.io:accept', 1);
|
||||||
socket.once('disconnect', () => counters.add('socket.io:disconnect', 1));
|
socket.once('disconnect', (reason, reasonDetail) => {
|
||||||
|
LOGGER.info(
|
||||||
|
'%s disconnected (%s%s)',
|
||||||
|
socket.context.ipAddress,
|
||||||
|
reason,
|
||||||
|
reasonDetail ? ` - ${reasonDetail}` : ''
|
||||||
|
);
|
||||||
|
counters.add('socket.io:disconnect', 1);
|
||||||
|
});
|
||||||
|
|
||||||
const user = new User(socket, socket.context.ipAddress, socket.context.user);
|
const user = new User(socket, socket.context.ipAddress, socket.context.user);
|
||||||
if (socket.context.user) {
|
if (socket.context.user) {
|
||||||
|
|
Loading…
Reference in New Issue