Compare commits

..

12 Commits

Author SHA1 Message Date
20a41d3381 1.0.26 2018-12-13 00:19:50 +01:00
b2019b33f8 fix(core): update 2018-12-13 00:19:50 +01:00
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
b2d4b82532 1.0.23 2018-11-25 22:02:57 +01:00
63713f4cd2 fix(core): update 2018-11-25 22:02:57 +01:00
5d3bc13126 1.0.22 2018-11-11 02:00:41 +01:00
4b30234cb6 fix(core): update 2018-11-11 02:00:40 +01:00
271971a373 1.0.21 2018-11-10 01:48:44 +01:00
d636dab664 fix(clean up old indices): update 2018-11-10 01:48:44 +01:00
7 changed files with 292 additions and 71 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

194
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.20", "version": "1.0.26",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -75,16 +75,34 @@
} }
}, },
"@pushrocks/lik": { "@pushrocks/lik": {
"version": "3.0.1", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/lik/-/lik-3.0.1.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/lik/-/lik-3.0.2.tgz",
"integrity": "sha512-6dwRg7WMdY9drlqfo6NzOcw5ubVWYvIOSSMZz4Jsojpa8aDVwXd2VkD7sxO/PJRrbZzHkx/JXoY/epcWRjngUw==", "integrity": "sha512-E2kI0jmPBGVfvXpmGEZOiv7amZrAIBpI49WL/gIdMy9MVeo6+k2VLDvYtdjzayVviE+LEt3//Xe08xE74FbP1A==",
"requires": { "requires": {
"@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@types/lodash": "^4.14.112", "@pushrocks/smartrx": "^2.0.2",
"@pushrocks/smarttime": "^3.0.5",
"@types/minimatch": "^3.0.3", "@types/minimatch": "^3.0.3",
"lodash": "^4.17.10",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"symbol-tree": "^3.2.2" "symbol-tree": "^3.2.2"
},
"dependencies": {
"@pushrocks/smarttime": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/@pushrocks/smarttime/-/smarttime-3.0.5.tgz",
"integrity": "sha512-nHjJ8xRZ87OE8tBBIAOgjHJmJrc3MaPZtEZ5JDY2U9gjaED6JdRcdQ+vhSaLJT+U2u8YzXOuA6LfNN+X4jZm6A==",
"requires": {
"@pushrocks/smartpromise": "^2.0.5",
"@types/luxon": "^1.4.1",
"luxon": "^1.8.0"
}
},
"luxon": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.8.0.tgz",
"integrity": "sha512-F742cYUYB7X+LXY3cIn6THZUBqRBjeAvF+CWE2i3+eKcv2bzsCsnRsBYL8Qrqzp1dfs6HsVcSjfKt2RcrtUElw=="
}
} }
}, },
"@pushrocks/qenv": { "@pushrocks/qenv": {
@ -187,6 +205,17 @@
"form-data": "^2.3.2" "form-data": "^2.3.2"
} }
}, },
"@pushrocks/smartrx": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smartrx/-/smartrx-2.0.2.tgz",
"integrity": "sha512-3lQONWp/Q/al8O6Cm9v6aSamNAzJimGHNFgHBKKmyBOVZaYrvhd6OMgDDicHE6vkYHXNtltXj5q3aIunz+bKwQ==",
"requires": {
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartpromise": "^2.0.5",
"rxjs": "^6.3.3",
"smartevent": "^1.0.1"
}
},
"@pushrocks/smartshell": { "@pushrocks/smartshell": {
"version": "2.0.8", "version": "2.0.8",
"resolved": "https://registry.npmjs.org/@pushrocks/smartshell/-/smartshell-2.0.8.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/smartshell/-/smartshell-2.0.8.tgz",
@ -198,6 +227,16 @@
"which": "^1.3.1" "which": "^1.3.1"
} }
}, },
"@pushrocks/smarttime": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smarttime/-/smarttime-3.0.2.tgz",
"integrity": "sha512-tFo2GZDwNa14umK3fNglvj9G/S981TSS1VZAMlIw7z43uMysbbJtjb8qpo625CilxEbi7D+RcyW5PJbCH2Wf6g==",
"requires": {
"@pushrocks/smartpromise": "^2.0.5",
"@types/luxon": "^1.4.0",
"luxon": "^1.4.3"
}
},
"@pushrocks/tapbundle": { "@pushrocks/tapbundle": {
"version": "3.0.7", "version": "3.0.7",
"resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.7.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.7.tgz",
@ -255,10 +294,10 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/lodash": { "@types/luxon": {
"version": "4.14.118", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.118.tgz", "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-1.4.1.tgz",
"integrity": "sha512-iiJbKLZbhSa6FYRip/9ZDX6HXhayXLDGY2Fqws9cOkEQ6XeKfaxB0sC541mowZJueYyMnVUmmG+al5/4fCDrgw==" "integrity": "sha512-mYv/gbkOJ40CDgR8st5sosfFNrJncdlkpdzQSNRdU86UQg3oWWmll4AO/7B8F5FlBC6YrIXqXDSnkoCBqo+uMA=="
}, },
"@types/minimatch": { "@types/minimatch": {
"version": "3.0.3", "version": "3.0.3",
@ -506,6 +545,14 @@
"type-detect": "^4.0.0" "type-detect": "^4.0.0"
} }
}, },
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
"integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==",
"requires": {
"object-keys": "^1.0.12"
}
},
"delayed-stream": { "delayed-stream": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@ -528,6 +575,28 @@
"lodash": "^4.17.10" "lodash": "^4.17.10"
} }
}, },
"es-abstract": {
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz",
"integrity": "sha512-C8Fx/0jFmV5IPoMOFPA9P9G5NtqW+4cOPit3MIuvR2t7Ag2K15EJTpxnHAYTzL+aYQJIESYeXZmDBfOBE1HcpA==",
"requires": {
"es-to-primitive": "^1.1.1",
"function-bind": "^1.1.1",
"has": "^1.0.1",
"is-callable": "^1.1.3",
"is-regex": "^1.0.4"
}
},
"es-to-primitive": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz",
"integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==",
"requires": {
"is-callable": "^1.1.4",
"is-date-object": "^1.0.1",
"is-symbol": "^1.0.2"
}
},
"es6-error": { "es6-error": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz",
@ -586,6 +655,11 @@
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true "dev": true
}, },
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"get-func-name": { "get-func-name": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
@ -612,6 +686,14 @@
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
"dev": true "dev": true
}, },
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"requires": {
"function-bind": "^1.1.1"
}
},
"has-ansi": { "has-ansi": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
@ -626,6 +708,11 @@
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true "dev": true
}, },
"has-symbols": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz",
"integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q="
},
"humanize-ms": { "humanize-ms": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz",
@ -650,6 +737,32 @@
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true "dev": true
}, },
"is-callable": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz",
"integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA=="
},
"is-date-object": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz",
"integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY="
},
"is-regex": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz",
"integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=",
"requires": {
"has": "^1.0.1"
}
},
"is-symbol": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz",
"integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==",
"requires": {
"has-symbols": "^1.0.0"
}
},
"is-utf8": { "is-utf8": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
@ -717,6 +830,11 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
}, },
"luxon": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.5.0.tgz",
"integrity": "sha512-9IfJ0a5jA3poJSQnamaoOdPG0ulYk1JUI5IYmEdUhUc8dto4t6TVTu+oIM7fpSYy01GwUAA8kGUZMVe7Qx9Y+Q=="
},
"make-error": { "make-error": {
"version": "1.3.5", "version": "1.3.5",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz",
@ -780,6 +898,20 @@
"integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA==", "integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA==",
"dev": true "dev": true
}, },
"object-keys": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz",
"integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag=="
},
"object.getownpropertydescriptors": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz",
"integrity": "sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY=",
"requires": {
"define-properties": "^1.1.2",
"es-abstract": "^1.5.1"
}
},
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -861,6 +993,14 @@
"path-parse": "^1.0.5" "path-parse": "^1.0.5"
} }
}, },
"rxjs": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires": {
"tslib": "^1.9.0"
}
},
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -887,6 +1027,23 @@
"chai-string": "^1.4.0" "chai-string": "^1.4.0"
} }
}, },
"smartevent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/smartevent/-/smartevent-1.0.1.tgz",
"integrity": "sha1-E9K/LPCU698XgT+g1GBB+BejAqo=",
"requires": {
"smartq": "^1.1.1",
"typings-global": "^1.0.16"
}
},
"smartq": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/smartq/-/smartq-1.1.8.tgz",
"integrity": "sha512-FURlYW/C3bLeZjJcBVyw7bxCyQoCXiXbLCZcDUKznhXHaLu35c8m33/a2H8CA0rtb82lvzN8dRLnBZAcNMzNHQ==",
"requires": {
"util.promisify": "^1.0.0"
}
},
"source-map": { "source-map": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -983,8 +1140,7 @@
"tslib": { "tslib": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
"dev": true
}, },
"tslint": { "tslint": {
"version": "5.11.0", "version": "5.11.0",
@ -1064,6 +1220,11 @@
"integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==", "integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==",
"dev": true "dev": true
}, },
"typings-global": {
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/typings-global/-/typings-global-1.0.28.tgz",
"integrity": "sha512-6VOwJWEY2971HOMHu/7sURzUXiD4/LiMJPsMAOqkHHAtS3MVpLFE5gzTiHilsH9KY5VE1mBQirWIgWFsDuo90A=="
},
"universalify": { "universalify": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
@ -1076,6 +1237,15 @@
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true "dev": true
}, },
"util.promisify": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/util.promisify/-/util.promisify-1.0.0.tgz",
"integrity": "sha512-i+6qA2MPhvoKLuxnJNpXAGhg7HphQOSUq2LKMZD0m15EiskXUkMvKdF4Uui0WYeCUGea+o2cw/ZuwehtfsrNkA==",
"requires": {
"define-properties": "^1.1.2",
"object.getownpropertydescriptors": "^2.0.3"
}
},
"vinyl": { "vinyl": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.2.0.tgz", "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.2.0.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.20", "version": "1.0.26",
"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",
@ -23,10 +23,11 @@
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.1", "@pushrocks/lik": "^3.0.2",
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartlog-interfaces": "^2.0.2", "@pushrocks/smartlog-interfaces": "^2.0.2",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smarttime": "^3.0.2",
"@types/elasticsearch": "^5.0.28", "@types/elasticsearch": "^5.0.28",
"elasticsearch": "^15.2.0" "elasticsearch": "^15.2.0"
} }

View File

@ -8,6 +8,8 @@ let testElasticLog: elasticsearch.ElasticSearch<any>;
tap.test('first test', async () => { tap.test('first test', async () => {
testElasticLog = new elasticsearch.ElasticSearch({ testElasticLog = new elasticsearch.ElasticSearch({
indexPrefix: 'smartlog',
indexRetention: 7,
domain: process.env.ELK_DOMAIN, domain: process.env.ELK_DOMAIN,
port: parseInt(process.env.ELK_PORT, 10), port: parseInt(process.env.ELK_PORT, 10),
ssl: true, ssl: true,

View File

@ -14,32 +14,93 @@ export class ElasticIndex {
public async ensureIndex(indexArg: string) { public async ensureIndex(indexArg: string) {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
if(this.stringmap.checkString(indexArg)) { if (this.stringmap.checkString(indexArg)) {
done.resolve();
return; return;
} }
this.elasticSearchRef.client.cat.indices({ this.elasticSearchRef.client.cat.indices(
format: 'json', {
bytes: 'm' format: 'json',
}, async (err, response: any[]) => { bytes: 'm'
// console.log(response); },
const index = response.find(indexObject => { async (err, responseArg: any[]) => {
return indexObject.index === indexArg; if(err) {
}); console.log(err);
return;
}
if(!index) { // lets delete indexes that violate the retention
const done2 = plugins.smartpromise.defer(); if(Array.isArray(responseArg)) {
this.elasticSearchRef.client.indices.create({ const filteredIndices = responseArg.filter(indexObjectArg => {
waitForActiveShards: '2', return indexObjectArg.index.startsWith('smartlog');
index: indexArg });
}, (error, response) => { const filteredIndexNames = filteredIndices.map(indexObjectArg => {
// console.lof(response) return indexObjectArg.index;
done2.resolve(); });
}); this.deleteOldIndices(filteredIndexNames);
await done2.promise; }
let index = null;
if(Array.isArray(responseArg)) {
index = responseArg.find(indexObject => {
return indexObject.index === indexArg;
});
}
if (!index) {
const done2 = plugins.smartpromise.defer();
this.elasticSearchRef.client.indices.create(
{
waitForActiveShards: '1',
index: indexArg
},
(error, response) => {
// console.lof(response)
done2.resolve();
}
);
await done2.promise;
}
this.stringmap.addString(indexArg);
done.resolve();
} }
this.stringmap.addString(indexArg); );
done.resolve();
});
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

@ -11,7 +11,9 @@ export interface IStandardLogParams {
severity: string; severity: string;
} }
export interface IElasticLogConstructorOptions { export interface IElasticSearchConstructorOptions {
indexPrefix: string;
indexRetention: number;
port: number; port: number;
domain: string; domain: string;
ssl: boolean; ssl: boolean;
@ -24,22 +26,27 @@ export class ElasticSearch<T> {
public elasticScheduler = new ElasticScheduler(this); public elasticScheduler = new ElasticScheduler(this);
public elasticIndex: ElasticIndex = new ElasticIndex(this); public elasticIndex: ElasticIndex = new ElasticIndex(this);
public indexPrefix: string;
public indexRetention: number;
/** /**
* sets up an instance of Elastic log * sets up an instance of Elastic log
* @param optionsArg * @param optionsArg
*/ */
constructor(optionsArg: IElasticLogConstructorOptions) { 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.indexRetention = optionsArg.indexRetention;
} }
/** /**
* computes the host string from the constructor options * computes the host string from the constructor options
* @param optionsArg * @param optionsArg
*/ */
private computeHostString(optionsArg: IElasticLogConstructorOptions): string { private computeHostString(optionsArg: IElasticSearchConstructorOptions): string {
let hostString = `${optionsArg.domain}:${optionsArg.port}`; let hostString = `${optionsArg.domain}:${optionsArg.port}`;
if (optionsArg.user && optionsArg.pass) { if (optionsArg.user && optionsArg.pass) {
hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`; hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`;
@ -54,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 = `smartlog-${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);
@ -81,17 +88,17 @@ export class ElasticSearch<T> {
console.log(error); console.log(error);
this.elasticScheduler.addFailedDoc(logPackageArg); this.elasticScheduler.addFailedDoc(logPackageArg);
} else { } else {
console.log(`ElasticLog: ${logPackageArg.message}`); // console.log(`ElasticLog: ${logPackageArg.message}`);
} }
} }
); );
} }
get logDestination (): ILogDestination { get logDestination(): ILogDestination {
return { return {
handleLog: (smartlogPackageArg: ILogPackage) => { handleLog: (smartlogPackageArg: ILogPackage) => {
this.log(smartlogPackageArg); this.log(smartlogPackageArg);
} }
} };
} }
} }

View File

@ -1,6 +1,8 @@
import * as elasticsearch from 'elasticsearch'; import * as elasticsearch from 'elasticsearch';
import * as lik from '@pushrocks/lik';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces'; import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smarttime from '@pushrocks/smarttime';
export { elasticsearch, smartdelay, smartlogInterfaces, smartpromise }; export { elasticsearch, lik, smartdelay, smartlogInterfaces, smartpromise, smarttime };