Compare commits

...

4 Commits

Author SHA1 Message Date
1ab582db51 1.0.25 2018-11-26 12:24:38 +01:00
9c87f5ee5e fix(core): update 2018-11-26 12:24:37 +01:00
ef9cb193d5 1.0.24 2018-11-25 22:06:25 +01:00
9f706e0a70 fix(core): update 2018-11-25 22:06:25 +01:00
5 changed files with 65 additions and 67 deletions

View File

@ -37,18 +37,6 @@ snyk:
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLEGACY:
stage: test
script:
- npmci npm prepare
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS: testLTS:
stage: test stage: test
@ -135,13 +123,3 @@ pages:
paths: paths:
- public - public
allow_failure: true allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.23", "version": "1.0.25",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.23", "version": "1.0.25",
"private": false, "private": false,
"description": "log to elasticsearch in a kibana compatible format", "description": "log to elasticsearch in a kibana compatible format",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -23,44 +23,30 @@ export class ElasticIndex {
format: 'json', format: 'json',
bytes: 'm' bytes: 'm'
}, },
async (err, response: any[]) => { async (err, responseArg: any[]) => {
if(err) {
console.log(err);
return;
}
// lets delete indexes that violate the retention // lets delete indexes that violate the retention
const filteredIndices = response.filter(indexObjectArg => { if(Array.isArray(responseArg)) {
const filteredIndices = responseArg.filter(indexObjectArg => {
return indexObjectArg.index.startsWith('smartlog'); return indexObjectArg.index.startsWith('smartlog');
}); });
const filteredIndexNames = filteredIndices.map(indexObjectArg => { const filteredIndexNames = filteredIndices.map(indexObjectArg => {
return indexObjectArg.index; return indexObjectArg.index;
}); });
const todayAsUnix: number = Date.now(); this.deleteOldIndices(filteredIndexNames);
const rententionPeriodAsUnix: number = plugins.smarttime.units.days(
this.elasticSearchRef.indexRetention
);
console.log(filteredIndexNames);
for (const indexName of filteredIndexNames) {
const regexResult = /^smartlog-([0-9]*)\.([0-9]*)\.([0-9]*)$/.exec(indexName);
const dateAsUnix: number = new Date(
`${regexResult[1]}-${regexResult[2]}-${regexResult[3]}`
).getTime();
if (todayAsUnix - rententionPeriodAsUnix > dateAsUnix) {
console.log(`found old index ${indexName}`);
const done2 = plugins.smartpromise.defer();
this.elasticSearchRef.client.indices.delete({
index: indexName
}, (err2, response2) => {
if(err2) {
console.log(err2);
}
console.log(`deleted ${indexName}`);
done2.resolve();
});
await done2.promise;
}
} }
// console.log(response); let index = null;
const index = response.find(indexObject => {
if(Array.isArray(responseArg)) {
index = responseArg.find(indexObject => {
return indexObject.index === indexArg; return indexObject.index === indexArg;
}); });
}
if (!index) { if (!index) {
const done2 = plugins.smartpromise.defer(); const done2 = plugins.smartpromise.defer();
@ -82,4 +68,38 @@ export class ElasticIndex {
); );
await done.promise; await done.promise;
} }
public createNewIndex(indexNameArg: string) {
}
public async deleteOldIndices(indicesArray: string[]) {
const todayAsUnix: number = Date.now();
const rententionPeriodAsUnix: number = plugins.smarttime.units.days(
this.elasticSearchRef.indexRetention
);
for (const indexName of indicesArray) {
const regexResult = /^smartlog-([0-9]*)\.([0-9]*)\.([0-9]*)$/.exec(indexName);
const dateAsUnix: number = new Date(
`${regexResult[1]}-${regexResult[2]}-${regexResult[3]}`
).getTime();
if (todayAsUnix - rententionPeriodAsUnix > dateAsUnix) {
console.log(`found old index ${indexName}`);
const done2 = plugins.smartpromise.defer();
this.elasticSearchRef.client.indices.delete(
{
index: indexName
},
(err2, response2) => {
if (err2) {
console.log(err2);
}
console.log(`deleted ${indexName}`);
done2.resolve();
}
);
await done2.promise;
}
}
}
} }

View File

@ -35,7 +35,7 @@ export class ElasticSearch<T> {
*/ */
constructor(optionsArg: IElasticSearchConstructorOptions) { constructor(optionsArg: IElasticSearchConstructorOptions) {
this.client = new ElasticClient({ this.client = new ElasticClient({
host: this.computeHostString(optionsArg), host: this.computeHostString(optionsArg)
// log: 'trace' // log: 'trace'
}); });
this.indexPrefix = optionsArg.indexPrefix; this.indexPrefix = optionsArg.indexPrefix;
@ -61,10 +61,10 @@ export class ElasticSearch<T> {
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) { public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
const now = new Date(); const now = new Date();
const indexToUse = `${this.indexPrefix}-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(-2)}.${( const indexToUse = `${this.indexPrefix}-${now.getFullYear()}.${(
'0' + now.getDate() '0' +
).slice(-2)}`; (now.getMonth() + 1)
).slice(-2)}.${('0' + now.getDate()).slice(-2)}`;
if (this.elasticScheduler.docsScheduled && !scheduleOverwrite) { if (this.elasticScheduler.docsScheduled && !scheduleOverwrite) {
this.elasticScheduler.scheduleDoc(logPackageArg); this.elasticScheduler.scheduleDoc(logPackageArg);
@ -99,6 +99,6 @@ export class ElasticSearch<T> {
handleLog: (smartlogPackageArg: ILogPackage) => { handleLog: (smartlogPackageArg: ILogPackage) => {
this.log(smartlogPackageArg); this.log(smartlogPackageArg);
} }
} };
} }
} }