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 InfoGetter = require("../get-info");
|
||||
var db = require("../database");
|
||||
var Media = require("../media");
|
||||
import { Counter, Summary } from 'prom-client';
|
||||
const LOGGER = require('@calzoneman/jsli')('channel/library');
|
||||
|
||||
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) {
|
||||
if (!this.channel.is(Flags.C_REGISTERED)) {
|
||||
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) {
|
||||
var query = data.query.substring(0, 100);
|
||||
var searchYT = function () {
|
||||
librarySearchQueryCount.labels('yt').inc(1, new Date());
|
||||
InfoGetter.Getters.ytSearch(query, function (e, vids) {
|
||||
if (!e) {
|
||||
librarySearchResultSize.labels('yt')
|
||||
.observe(vids.length, new Date());
|
||||
user.socket.emit("searchResults", {
|
||||
source: "yt",
|
||||
results: vids
|
||||
|
@ -98,11 +100,16 @@ LibraryModule.prototype.handleSearchMedia = function (user, data) {
|
|||
!this.channel.modules.permissions.canSeePlaylist(user)) {
|
||||
searchYT();
|
||||
} else {
|
||||
librarySearchQueryCount.labels('library').inc(1, new Date());
|
||||
|
||||
db.channels.searchLibrary(this.channel.name, query, function (err, res) {
|
||||
if (err) {
|
||||
res = [];
|
||||
}
|
||||
|
||||
librarySearchResultSize.labels('library')
|
||||
.observe(res.length, new Date());
|
||||
|
||||
if (res.length === 0) {
|
||||
return searchYT();
|
||||
}
|
||||
|
|
|
@ -394,10 +394,6 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
|
|||
|
||||
var id = data.id;
|
||||
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") {
|
||||
return;
|
||||
|
@ -522,29 +518,6 @@ PlaylistModule.prototype.queueStandard = function (user, data) {
|
|||
this.channel.refCounter.ref("PlaylistModule::queueStandard");
|
||||
counters.add("playlist:queue:count", 1);
|
||||
this.semaphore.queue(function (lock) {
|
||||
var lib = self.channel.modules.library;
|
||||
if (lib && self.channel.is(Flags.C_REGISTERED) && !util.isLive(data.type)) {
|
||||
// TODO: remove this check entirely once metrics are collected.
|
||||
lib.getItem(data.id, function (err, item) {
|
||||
if (err && err !== "Item not in library") {
|
||||
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();
|
||||
});
|
||||
} else {
|
||||
handleLookup();
|
||||
}
|
||||
|
||||
function handleLookup() {
|
||||
InfoGetter.getMedia(data.id, data.type, function (err, media) {
|
||||
if (err) {
|
||||
error(XSS.sanitizeText(String(err)));
|
||||
|
@ -557,7 +530,6 @@ PlaylistModule.prototype.queueStandard = function (user, data) {
|
|||
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -229,7 +229,15 @@ class IOServer {
|
|||
|
||||
LOGGER.info('Accepted socket from %s', socket.context.ipAddress);
|
||||
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);
|
||||
if (socket.context.user) {
|
||||
|
|
Loading…
Reference in New Issue