Compare commits
78 Commits
Author | SHA1 | Date | |
---|---|---|---|
cdbf1fd316 | |||
10108d8338 | |||
36abb2c7c0 | |||
8f00d90bb1 | |||
41f1758d46 | |||
2b7cd33996 | |||
80a04ca893 | |||
93f739c79e | |||
a1b5bf5c0c | |||
084c5d137c | |||
4aa0592bd5 | |||
0313e5045a | |||
7442d93f58 | |||
35e70aae62 | |||
cc30f43a28 | |||
100a8fc12e | |||
f32403961d | |||
9734949241 | |||
b70444824b | |||
0eb0903667 | |||
4d11dca22c | |||
3079adbbd9 | |||
bc9de8e4d6 | |||
3fa7d66236 | |||
2a0b0b2478 | |||
35e99663a4 | |||
2cc5855206 | |||
8f9f2fdf05 | |||
7ef36b5c40 | |||
67a8f3fe4d | |||
5ae2c37519 | |||
fcb67ec878 | |||
9e25494f8f | |||
dd8ba4736a | |||
d395310410 | |||
49233ce45f | |||
fb93dce8bc | |||
30cbc05aa2 | |||
2a595a1a9a | |||
d62b18e93c | |||
d6176f820a | |||
0ebc1d5288 | |||
2b0003546a | |||
60617f2fca | |||
9c767d07e4 | |||
f3aa94dcb7 | |||
a0be0edd9d | |||
ad24ba2f5d | |||
b0cf4bb27f | |||
fd29ceab80 | |||
bcca434a24 | |||
d4a9ad8f67 | |||
d4c7c33668 | |||
8340257b00 | |||
32265e83f3 | |||
e2df11cea2 | |||
2719ba28f6 | |||
6d78a7ba0c | |||
5897c6e7de | |||
20369614a2 | |||
7ceaf694fe | |||
391c6bd45d | |||
1a702071c6 | |||
0fe2f6a4ae | |||
20d04413c9 | |||
e56439e9f4 | |||
c9a9434cd9 | |||
5d98dd9089 | |||
2d635fdf7c | |||
1dbf3724d0 | |||
cc7eb8c139 | |||
0e01ecbd1a | |||
2d21b40a76 | |||
2d1a5cdc50 | |||
20a41d3381 | |||
b2019b33f8 | |||
1ab582db51 | |||
9c87f5ee5e |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,5 +1,20 @@
|
|||||||
.nogit/
|
.nogit/
|
||||||
node_modules/
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
120
.gitlab-ci.yml
120
.gitlab-ci.yml
@ -1,119 +1,119 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
snyk:
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm install -g snyk
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm install
|
||||||
- npmci node install lts
|
- npmci npm test
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm install
|
||||||
- npmci node install stable
|
- npmci npm build
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci npm publish
|
||||||
- npmci npm publish
|
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install stable
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -121,5 +121,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.12.0
|
|
||||||
ignore: {}
|
|
||||||
patch: {}
|
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -2,5 +2,16 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "mojoio",
|
||||||
|
"gitrepo": "elasticsearch",
|
||||||
|
"description": "log to elasticsearch in a kibana compatible format",
|
||||||
|
"npmPackagename": "@mojoio/elasticsearch",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1298
package-lock.json
generated
1298
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@ -1,34 +1,48 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/elasticsearch",
|
"name": "@apiclient.xyz/elasticsearch",
|
||||||
"version": "1.0.24",
|
"version": "2.0.6",
|
||||||
"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_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"format": "(gitzone format)",
|
"format": "(gitzone format)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsrun": "^1.1.13",
|
"@gitzone/tsrun": "^1.2.42",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.74",
|
||||||
"@pushrocks/qenv": "^2.0.2",
|
"@pushrocks/qenv": "^5.0.2",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^5.0.8",
|
||||||
"@types/node": "^10.12.2",
|
"@types/node": "^20.3.3"
|
||||||
"tslint": "^5.11.0",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.2",
|
"@elastic/elasticsearch": "7.17.11-patch.1",
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/lik": "^6.0.2",
|
||||||
"@pushrocks/smartlog-interfaces": "^2.0.2",
|
"@pushrocks/smartdelay": "^3.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartlog-interfaces": "^3.0.0",
|
||||||
"@pushrocks/smarttime": "^3.0.2",
|
"@pushrocks/smartpromise": "^4.0.2",
|
||||||
"@types/elasticsearch": "^5.0.28",
|
"@pushrocks/smarttime": "^4.0.1"
|
||||||
"elasticsearch": "^15.2.0"
|
},
|
||||||
}
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
4573
pnpm-lock.yaml
generated
Normal file
4573
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
readme.md
50
readme.md
@ -1,26 +1,26 @@
|
|||||||
# elasticlog
|
# @mojoio/elasticsearch
|
||||||
|
|
||||||
log to elasticsearch in a kibana compatible format
|
log to elasticsearch in a kibana compatible format
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/elasticsearch)
|
||||||
[](https://www.npmjs.com/package/elasticlog)
|
* [gitlab.com (source)](https://gitlab.com/mojoio/elasticsearch)
|
||||||
[](https://GitLab.com/pushrocks/elasticlog)
|
* [github.com (source mirror)](https://github.com/mojoio/elasticsearch)
|
||||||
[](https://github.com/pushrocks/elasticlog)
|
* [docs (typedoc)](https://mojoio.gitlab.io/elasticsearch/)
|
||||||
[](https://pushrocks.gitlab.io/elasticlog/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/elasticlog/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://GitLab.com/pushrocks/elasticlog/commits/master)
|
-- | --
|
||||||
[](https://www.npmjs.com/package/elasticlog)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://david-dm.org/pushrocks/elasticlog)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/elasticlog/master/dependencies/npm)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/elasticlog)
|
Snyk | [](https://lossless.cloud)
|
||||||
[](https://snyk.io/test/npm/elasticlog)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
Code Style | [](https://lossless.cloud)
|
||||||
[](http://standardjs.com/)
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -32,3 +32,17 @@ For further information read the linked docs at the top of this README.
|
|||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://push.rocks)
|
||||||
|
|
||||||
|
## Contribute
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. + Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: [Contribute monthly :)](https://lossless.link/contribute)
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
0
test/00tapwrap.ts
Normal file
0
test/00tapwrap.ts
Normal file
89
test/test.nonci.ts
Normal file
89
test/test.nonci.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
import * as elasticsearch from '../ts/index.js';
|
||||||
|
|
||||||
|
let testElasticLog: elasticsearch.ElsSmartlogDestination<any>;
|
||||||
|
let testElasticDoc: elasticsearch.ElasticDoc;
|
||||||
|
|
||||||
|
tap.test('first test', async () => {
|
||||||
|
testElasticLog = new elasticsearch.ElsSmartlogDestination({
|
||||||
|
indexPrefix: 'testprefix',
|
||||||
|
indexRetention: 7,
|
||||||
|
node: 'http://localhost:9200',
|
||||||
|
auth: {
|
||||||
|
username: 'elastic',
|
||||||
|
password: 'YourPassword'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElsSmartlogDestination);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send a message to Elasticsearch', async () => {
|
||||||
|
await testElasticLog.log({
|
||||||
|
timestamp: Date.now(),
|
||||||
|
type: 'increment',
|
||||||
|
level: 'info',
|
||||||
|
context: {
|
||||||
|
company: 'Lossless GmbH',
|
||||||
|
companyunit: 'lossless.cloud',
|
||||||
|
containerName: 'testcontainer',
|
||||||
|
environment: 'test',
|
||||||
|
runtime: 'node',
|
||||||
|
zone: 'ship.zone',
|
||||||
|
},
|
||||||
|
message: 'GET https://myroute.to.a.cool.destination/sorare?hello=there',
|
||||||
|
correlation: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create an ElasticDoc instance', async () => {
|
||||||
|
testElasticDoc = new elasticsearch.ElasticDoc({
|
||||||
|
index: 'testindex',
|
||||||
|
node: 'http://localhost:9200',
|
||||||
|
auth: {
|
||||||
|
username: 'elastic',
|
||||||
|
password: 'YourPassword'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(testElasticDoc).toBeInstanceOf(elasticsearch.ElasticDoc);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should add and update documents in a piping session', async () => {
|
||||||
|
await testElasticDoc.startPipingSession({});
|
||||||
|
await testElasticDoc.pipeDocument({
|
||||||
|
docId: '1',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
doc: { name: 'doc1' }
|
||||||
|
});
|
||||||
|
await testElasticDoc.pipeDocument({
|
||||||
|
docId: '2',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
doc: { name: 'doc2' }
|
||||||
|
});
|
||||||
|
await testElasticDoc.pipeDocument({
|
||||||
|
docId: '1',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
doc: { name: 'updated doc1' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should delete documents not part of the piping session', async () => {
|
||||||
|
await testElasticDoc.endPipingSession();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should take and store snapshot', async () => {
|
||||||
|
await testElasticDoc.takeSnapshot(async (iterator, prevSnapshot) => {
|
||||||
|
const aggregationData = [];
|
||||||
|
for await (const doc of iterator) {
|
||||||
|
// Sample aggregation: counting documents
|
||||||
|
aggregationData.push(doc);
|
||||||
|
}
|
||||||
|
const snapshot = {
|
||||||
|
date: new Date().toISOString(),
|
||||||
|
aggregationData,
|
||||||
|
};
|
||||||
|
return snapshot;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
39
test/test.ts
39
test/test.ts
@ -1,39 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
|
||||||
import * as elasticsearch from '../ts/index';
|
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit/');
|
|
||||||
|
|
||||||
let testElasticLog: elasticsearch.ElasticSearch<any>;
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
testElasticLog = new elasticsearch.ElasticSearch({
|
|
||||||
indexPrefix: 'smartlog',
|
|
||||||
indexRetention: 7,
|
|
||||||
domain: process.env.ELK_DOMAIN,
|
|
||||||
port: parseInt(process.env.ELK_PORT, 10),
|
|
||||||
ssl: true,
|
|
||||||
user: process.env.ELK_USER,
|
|
||||||
pass: process.env.ELK_PASS
|
|
||||||
});
|
|
||||||
expect(testElasticLog).to.be.instanceOf(elasticsearch.ElasticSearch);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should send a message to Elasticsearch', async () => {
|
|
||||||
testElasticLog.log({
|
|
||||||
timestamp: Date.now(),
|
|
||||||
type: 'increment',
|
|
||||||
level: 'info',
|
|
||||||
context: {
|
|
||||||
company: 'Lossless GmbH',
|
|
||||||
companyunit: 'lossless.cloud',
|
|
||||||
containerName: 'testcontainer',
|
|
||||||
environment: 'test',
|
|
||||||
runtime: 'node',
|
|
||||||
zone: 'ship.zone'
|
|
||||||
},
|
|
||||||
message: 'hi, this is a testMessage'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@apiclient.xyz/elasticsearch',
|
||||||
|
version: '2.0.6',
|
||||||
|
description: 'log to elasticsearch in a kibana compatible format'
|
||||||
|
}
|
@ -1,88 +0,0 @@
|
|||||||
import * as plugins from './elasticsearch.plugins';
|
|
||||||
import { ElasticSearch } from './elasticsearch.classes.elasticsearch';
|
|
||||||
import { ILogPackage } from '@pushrocks/smartlog-interfaces';
|
|
||||||
|
|
||||||
import { Stringmap } from '@pushrocks/lik';
|
|
||||||
|
|
||||||
export class ElasticIndex {
|
|
||||||
private stringmap = new Stringmap();
|
|
||||||
private elasticSearchRef: ElasticSearch<any>;
|
|
||||||
|
|
||||||
constructor(elasticSearchInstanceArg: ElasticSearch<ILogPackage>) {
|
|
||||||
this.elasticSearchRef = elasticSearchInstanceArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ensureIndex(indexArg: string) {
|
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
if (this.stringmap.checkString(indexArg)) {
|
|
||||||
done.resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.elasticSearchRef.client.cat.indices(
|
|
||||||
{
|
|
||||||
format: 'json',
|
|
||||||
bytes: 'm'
|
|
||||||
},
|
|
||||||
async (err, response: any[]) => {
|
|
||||||
// lets delete indexes that violate the retention
|
|
||||||
const filteredIndices = response.filter(indexObjectArg => {
|
|
||||||
return indexObjectArg.index.startsWith('smartlog');
|
|
||||||
});
|
|
||||||
const filteredIndexNames = filteredIndices.map(indexObjectArg => {
|
|
||||||
return indexObjectArg.index;
|
|
||||||
});
|
|
||||||
const todayAsUnix: number = Date.now();
|
|
||||||
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);
|
|
||||||
const index = response.find(indexObject => {
|
|
||||||
return indexObject.index === indexArg;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!index) {
|
|
||||||
const done2 = plugins.smartpromise.defer();
|
|
||||||
this.elasticSearchRef.client.indices.create(
|
|
||||||
{
|
|
||||||
waitForActiveShards: '2',
|
|
||||||
index: indexArg
|
|
||||||
},
|
|
||||||
(error, response) => {
|
|
||||||
// console.lof(response)
|
|
||||||
done2.resolve();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
await done2.promise;
|
|
||||||
}
|
|
||||||
this.stringmap.addString(indexArg);
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
await done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
import { ElasticSearch, IStandardLogParams } from './elasticsearch.classes.elasticsearch';
|
|
||||||
|
|
||||||
export class ElasticScheduler {
|
|
||||||
elasticSearchRef: ElasticSearch<any>;
|
|
||||||
docsScheduled = false;
|
|
||||||
docsStorage: any[] = [];
|
|
||||||
|
|
||||||
constructor(elasticLogRefArg: ElasticSearch<any>) {
|
|
||||||
this.elasticSearchRef = elasticLogRefArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addFailedDoc(objectArg: any | IStandardLogParams) {
|
|
||||||
this.docsStorage.push(objectArg);
|
|
||||||
this.setRetry();
|
|
||||||
}
|
|
||||||
public scheduleDoc(logObject: any) {
|
|
||||||
this.docsStorage.push(logObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
public setRetry() {
|
|
||||||
setTimeout(() => {
|
|
||||||
const oldStorage = this.docsStorage;
|
|
||||||
this.docsStorage = [];
|
|
||||||
for (let logObject of oldStorage) {
|
|
||||||
this.elasticSearchRef.log(logObject, true);
|
|
||||||
}
|
|
||||||
if (this.docsStorage.length === 0) {
|
|
||||||
console.log('ElasticLog retry success!!!');
|
|
||||||
this.docsScheduled = false;
|
|
||||||
} else {
|
|
||||||
console.log('ElasticLog retry failed');
|
|
||||||
this.setRetry();
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public deferSend() {
|
|
||||||
if (!this.docsScheduled) {
|
|
||||||
console.log('Retry ElasticLog in 5 seconds!');
|
|
||||||
this.docsScheduled = true;
|
|
||||||
this.setRetry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
250
ts/els.classes.elasticdoc.ts
Normal file
250
ts/els.classes.elasticdoc.ts
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
|
export interface IElasticDocConstructorOptions {
|
||||||
|
index: string;
|
||||||
|
node: string;
|
||||||
|
auth?: {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISnapshot {
|
||||||
|
date: string;
|
||||||
|
aggregationData: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SnapshotProcessor = (
|
||||||
|
iterator: AsyncIterable<any>,
|
||||||
|
prevSnapshot: ISnapshot | null
|
||||||
|
) => Promise<ISnapshot>;
|
||||||
|
|
||||||
|
export class ElasticDoc {
|
||||||
|
public client: ElasticClient;
|
||||||
|
public index: string;
|
||||||
|
private sessionDocs: Set<string> = new Set();
|
||||||
|
private indexInitialized: boolean = false;
|
||||||
|
private latestTimestamp: string | null = null; // Store the latest timestamp
|
||||||
|
private onlyNew: boolean = false; // Whether to only pipe new docs
|
||||||
|
|
||||||
|
private BATCH_SIZE = 1000;
|
||||||
|
|
||||||
|
constructor(options: IElasticDocConstructorOptions) {
|
||||||
|
this.client = new ElasticClient({
|
||||||
|
node: options.node,
|
||||||
|
...(options.auth && { auth: options.auth }),
|
||||||
|
});
|
||||||
|
this.index = options.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ensureIndexExists(doc: any) {
|
||||||
|
if (!this.indexInitialized) {
|
||||||
|
const { body: indexExists } = await this.client.indices.exists({ index: this.index });
|
||||||
|
if (!indexExists) {
|
||||||
|
const mappings = this.createMappingsFromDoc(doc);
|
||||||
|
await this.client.indices.create({
|
||||||
|
index: this.index,
|
||||||
|
body: {
|
||||||
|
mappings,
|
||||||
|
settings: {
|
||||||
|
// You can define the settings according to your requirements here
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.indexInitialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private createMappingsFromDoc(doc: any): any {
|
||||||
|
const properties: any = {};
|
||||||
|
for (const key in doc) {
|
||||||
|
if (key === '@timestamp') {
|
||||||
|
properties[key] = { type: 'date' };
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
properties[key] = { type: typeof doc[key] === 'number' ? 'float' : 'text' };
|
||||||
|
}
|
||||||
|
return { properties };
|
||||||
|
}
|
||||||
|
|
||||||
|
async startPipingSession(options: { onlyNew?: boolean }) {
|
||||||
|
this.sessionDocs.clear();
|
||||||
|
this.onlyNew = options.onlyNew;
|
||||||
|
|
||||||
|
if (this.onlyNew) {
|
||||||
|
try {
|
||||||
|
const response = await this.client.search({
|
||||||
|
index: this.index,
|
||||||
|
sort: '@timestamp:desc',
|
||||||
|
size: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
// If the search query succeeded, the index exists.
|
||||||
|
const hit = response.body.hits.hits[0];
|
||||||
|
this.latestTimestamp = hit?._source?.['@timestamp'] || null;
|
||||||
|
|
||||||
|
if (this.latestTimestamp) {
|
||||||
|
console.log(`Working in "onlyNew" mode. Hence we are omitting documents prior to ${this.latestTimestamp}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Working in "onlyNew" mode, but no documents found in index ${this.index}. Hence processing all documents now.`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// If the search query failed, the index likely doesn't exist or some other error occurred.
|
||||||
|
if (e.meta && e.meta.statusCode === 404) {
|
||||||
|
console.log(`Index ${this.index} does not exist. Working in "onlyNew" mode, but will process all documents as the index is empty.`);
|
||||||
|
} else {
|
||||||
|
console.log(`An error occurred while trying to retrieve the latest timestamp: ${e}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.latestTimestamp = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async pipeDocument(optionsArg: { docId: string; timestamp?: string | number; doc: any }) {
|
||||||
|
await this.ensureIndexExists(optionsArg.doc);
|
||||||
|
|
||||||
|
const documentBody = {
|
||||||
|
...optionsArg.doc,
|
||||||
|
...(optionsArg.timestamp && { '@timestamp': optionsArg.timestamp }),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If 'onlyNew' is true, compare the document timestamp with the latest timestamp
|
||||||
|
if (this.onlyNew) {
|
||||||
|
if (this.latestTimestamp && optionsArg.timestamp <= this.latestTimestamp) {
|
||||||
|
// Omit the document
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
await this.client.index({
|
||||||
|
index: this.index,
|
||||||
|
id: optionsArg.docId,
|
||||||
|
body: documentBody,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.sessionDocs.add(optionsArg.docId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async endPipingSession() {
|
||||||
|
const allDocIds: string[] = [];
|
||||||
|
const responseQueue = [];
|
||||||
|
let response = await this.client.search({
|
||||||
|
index: this.index,
|
||||||
|
scroll: '1m',
|
||||||
|
size: this.BATCH_SIZE,
|
||||||
|
});
|
||||||
|
while (true) {
|
||||||
|
response.body.hits.hits.forEach((hit: any) => allDocIds.push(hit._id));
|
||||||
|
if (!response.body.hits.hits.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
response = await this.client.scroll({ scroll_id: response.body._scroll_id, scroll: '1m' });
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const docId of allDocIds) {
|
||||||
|
if (!this.sessionDocs.has(docId)) {
|
||||||
|
responseQueue.push({
|
||||||
|
delete: {
|
||||||
|
_index: this.index,
|
||||||
|
_id: docId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (responseQueue.length >= this.BATCH_SIZE) {
|
||||||
|
await this.client.bulk({ refresh: true, body: responseQueue });
|
||||||
|
responseQueue.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseQueue.length > 0) {
|
||||||
|
await this.client.bulk({ refresh: true, body: responseQueue });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sessionDocs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
async takeSnapshot(processIterator: SnapshotProcessor) {
|
||||||
|
const snapshotIndex = `${this.index}_snapshots`;
|
||||||
|
|
||||||
|
const { body: indexExists } = await this.client.indices.exists({ index: snapshotIndex });
|
||||||
|
if (!indexExists) {
|
||||||
|
await this.client.indices.create({
|
||||||
|
index: snapshotIndex,
|
||||||
|
body: {
|
||||||
|
mappings: {
|
||||||
|
properties: {
|
||||||
|
date: {
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
aggregationData: {
|
||||||
|
type: 'object',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const documentIterator = this.getDocumentIterator();
|
||||||
|
|
||||||
|
const newSnapshot = await processIterator(documentIterator, await this.getLastSnapshot());
|
||||||
|
|
||||||
|
await this.storeSnapshot(newSnapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getLastSnapshot(): Promise<ISnapshot | null> {
|
||||||
|
const snapshotIndex = `${this.index}_snapshots`;
|
||||||
|
const { body: indexExists } = await this.client.indices.exists({ index: snapshotIndex });
|
||||||
|
|
||||||
|
if (!indexExists) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.client.search({
|
||||||
|
index: snapshotIndex,
|
||||||
|
sort: 'date:desc',
|
||||||
|
size: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.body.hits.hits.length > 0) {
|
||||||
|
const hit = response.body.hits.hits[0];
|
||||||
|
return {
|
||||||
|
date: hit._source.date,
|
||||||
|
aggregationData: hit._source.aggregationData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async *getDocumentIterator() {
|
||||||
|
let response = await this.client.search({
|
||||||
|
index: this.index,
|
||||||
|
scroll: '1m',
|
||||||
|
size: this.BATCH_SIZE,
|
||||||
|
});
|
||||||
|
while (true) {
|
||||||
|
for (const hit of response.body.hits.hits) {
|
||||||
|
yield hit._source;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.body.hits.hits.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = await this.client.scroll({ scroll_id: response.body._scroll_id, scroll: '1m' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async storeSnapshot(snapshot: ISnapshot) {
|
||||||
|
await this.client.index({
|
||||||
|
index: `${this.index}_snapshots`,
|
||||||
|
body: snapshot,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
103
ts/els.classes.elasticindex.ts
Normal file
103
ts/els.classes.elasticindex.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import * as plugins from './els.plugins.js';
|
||||||
|
import { ElsSmartlogDestination } from './els.classes.smartlogdestination.js';
|
||||||
|
import { type ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||||
|
import { Stringmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
|
export class ElasticIndex {
|
||||||
|
private stringmap = new Stringmap();
|
||||||
|
private elasticSearchRef: ElsSmartlogDestination<any>;
|
||||||
|
|
||||||
|
constructor(elasticSearchInstanceArg: ElsSmartlogDestination<ILogPackage>) {
|
||||||
|
this.elasticSearchRef = elasticSearchInstanceArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ensureIndex(prefixArg: string, indexNameArg: string) {
|
||||||
|
if (this.stringmap.checkString(indexNameArg)) {
|
||||||
|
return indexNameArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseArg = await this.elasticSearchRef.client.cat.indices({
|
||||||
|
format: 'json',
|
||||||
|
bytes: 'm',
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!responseArg) {
|
||||||
|
throw new Error('Could not get valid response from elastic search');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(responseArg.body)) {
|
||||||
|
const filteredIndices = responseArg.body.filter((indexObjectArg) => {
|
||||||
|
return indexObjectArg.index.startsWith(prefixArg);
|
||||||
|
});
|
||||||
|
const filteredIndexNames = filteredIndices.map((indexObjectArg) => {
|
||||||
|
return indexObjectArg.index;
|
||||||
|
});
|
||||||
|
await this.deleteOldIndices(prefixArg, filteredIndexNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
let index = null;
|
||||||
|
|
||||||
|
if (Array.isArray(responseArg.body)) {
|
||||||
|
index = responseArg.body.find((indexItemArg) => {
|
||||||
|
return indexItemArg.index === indexNameArg;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!index) {
|
||||||
|
await this.createNewIndex(indexNameArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.stringmap.addString(indexNameArg);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createNewIndex(indexNameArg: string) {
|
||||||
|
const response = await this.elasticSearchRef.client.indices.create({
|
||||||
|
wait_for_active_shards: '1',
|
||||||
|
index: indexNameArg,
|
||||||
|
body: {
|
||||||
|
mappings: {
|
||||||
|
properties: {
|
||||||
|
'@timestamp': {
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
logPackageArg: {
|
||||||
|
properties: {
|
||||||
|
payload: {
|
||||||
|
type: 'object',
|
||||||
|
dynamic: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteOldIndices(prefixArg: string, indicesArray: string[]) {
|
||||||
|
const todayAsUnix: number = Date.now();
|
||||||
|
const rententionPeriodAsUnix: number = plugins.smarttime.units.days(
|
||||||
|
this.elasticSearchRef.indexRetention
|
||||||
|
);
|
||||||
|
for (const indexName of indicesArray) {
|
||||||
|
if (!indexName.startsWith(prefixArg)) continue;
|
||||||
|
const indexRegex = new RegExp(`^${prefixArg}-([0-9]*)-([0-9]*)-([0-9]*)$`)
|
||||||
|
const regexResult = indexRegex.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 response = await this.elasticSearchRef.client.indices.delete(
|
||||||
|
{
|
||||||
|
index: indexName,
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
ts/els.classes.elasticscheduler.ts
Normal file
63
ts/els.classes.elasticscheduler.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { ElsSmartlogDestination, type IStandardLogParams } from './els.classes.smartlogdestination.js';
|
||||||
|
|
||||||
|
export class ElasticScheduler {
|
||||||
|
elasticSearchRef: ElsSmartlogDestination<any>;
|
||||||
|
docsScheduled = false;
|
||||||
|
docsStorage: any[] = [];
|
||||||
|
|
||||||
|
// maximum size of the buffer
|
||||||
|
maxBufferSize = 500;
|
||||||
|
|
||||||
|
constructor(elasticLogRefArg: ElsSmartlogDestination<any>) {
|
||||||
|
this.elasticSearchRef = elasticLogRefArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addFailedDoc(objectArg: any | IStandardLogParams) {
|
||||||
|
this.addToStorage(objectArg);
|
||||||
|
this.setRetry();
|
||||||
|
}
|
||||||
|
|
||||||
|
public scheduleDoc(logObject: any) {
|
||||||
|
this.addToStorage(logObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private addToStorage(logObject: any) {
|
||||||
|
this.docsStorage.push(logObject);
|
||||||
|
|
||||||
|
// if buffer is full, send logs immediately
|
||||||
|
if (this.docsStorage.length >= this.maxBufferSize) {
|
||||||
|
this.flushLogsToElasticSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private flushLogsToElasticSearch() {
|
||||||
|
const oldStorage = this.docsStorage;
|
||||||
|
this.docsStorage = [];
|
||||||
|
|
||||||
|
for (let logObject of oldStorage) {
|
||||||
|
this.elasticSearchRef.log(logObject, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public setRetry() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.flushLogsToElasticSearch();
|
||||||
|
|
||||||
|
if (this.docsStorage.length === 0) {
|
||||||
|
console.log('ElasticLog retry success!!!');
|
||||||
|
this.docsScheduled = false;
|
||||||
|
} else {
|
||||||
|
console.log('ElasticLog retry failed');
|
||||||
|
this.setRetry();
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public deferSend() {
|
||||||
|
if (!this.docsScheduled) {
|
||||||
|
console.log('Retry ElasticLog in 5 seconds!');
|
||||||
|
this.docsScheduled = true;
|
||||||
|
this.setRetry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
ts/els.classes.fastpush.ts
Normal file
68
ts/els.classes.fastpush.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
|
interface FastPushOptions {
|
||||||
|
deleteOldData?: boolean; // Clear the index
|
||||||
|
deleteIndex?: boolean; // Delete the entire index
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FastPush {
|
||||||
|
private client: ElasticClient;
|
||||||
|
|
||||||
|
constructor(node: string, auth?: { username: string; password: string }) {
|
||||||
|
this.client = new ElasticClient({
|
||||||
|
node: node,
|
||||||
|
...(auth && { auth: auth }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async pushToIndex(indexName: string, docArray: any[], options?: FastPushOptions) {
|
||||||
|
if (docArray.length === 0) return;
|
||||||
|
|
||||||
|
const { body: indexExists } = await this.client.indices.exists({ index: indexName });
|
||||||
|
|
||||||
|
if (indexExists) {
|
||||||
|
if (options?.deleteIndex) {
|
||||||
|
await this.client.indices.delete({ index: indexName });
|
||||||
|
} else if (options?.deleteOldData) {
|
||||||
|
await this.client.deleteByQuery({
|
||||||
|
index: indexName,
|
||||||
|
body: {
|
||||||
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!indexExists || options?.deleteIndex) {
|
||||||
|
// Create index with mappings (for simplicity, we use dynamic mapping)
|
||||||
|
await this.client.indices.create({
|
||||||
|
index: indexName,
|
||||||
|
body: {
|
||||||
|
mappings: {
|
||||||
|
dynamic: "true"
|
||||||
|
// ... other specific mappings
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bulk insert documents
|
||||||
|
const bulkBody = [];
|
||||||
|
for (const doc of docArray) {
|
||||||
|
bulkBody.push({
|
||||||
|
index: {
|
||||||
|
_index: indexName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
bulkBody.push(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.client.bulk({ body: bulkBody });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage example:
|
||||||
|
// const fastPush = new FastPush('http://localhost:9200', { username: 'elastic', password: 'password' });
|
||||||
|
// fastPush.pushToIndex('my_index', [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }], { deleteOldData: true });
|
111
ts/els.classes.kvstore.ts
Normal file
111
ts/els.classes.kvstore.ts
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import * as plugins from './els.plugins.js';
|
||||||
|
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
|
export interface IElasticKVStoreConstructorOptions {
|
||||||
|
index: string;
|
||||||
|
node: string;
|
||||||
|
auth?: {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ElasticKVStore {
|
||||||
|
public client: ElasticClient;
|
||||||
|
public index: string;
|
||||||
|
private readyDeferred: any;
|
||||||
|
|
||||||
|
constructor(options: IElasticKVStoreConstructorOptions) {
|
||||||
|
this.client = new ElasticClient({
|
||||||
|
node: options.node,
|
||||||
|
...(options.auth && { auth: options.auth }),
|
||||||
|
});
|
||||||
|
this.index = options.index;
|
||||||
|
this.readyDeferred = plugins.smartpromise.defer();
|
||||||
|
this.setupIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async setupIndex() {
|
||||||
|
try {
|
||||||
|
const { body: indexExists } = await this.client.indices.exists({ index: this.index });
|
||||||
|
|
||||||
|
if (!indexExists) {
|
||||||
|
await this.client.indices.create({
|
||||||
|
index: this.index,
|
||||||
|
body: {
|
||||||
|
mappings: {
|
||||||
|
properties: {
|
||||||
|
key: {
|
||||||
|
type: 'keyword'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: 'text'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
} catch (err) {
|
||||||
|
this.readyDeferred.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async set(key: string, value: string) {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
await this.client.index({
|
||||||
|
index: this.index,
|
||||||
|
id: key,
|
||||||
|
body: {
|
||||||
|
key,
|
||||||
|
value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(key: string): Promise<string | null> {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.client.get({
|
||||||
|
index: this.index,
|
||||||
|
id: key
|
||||||
|
});
|
||||||
|
return response.body._source.value;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.meta && error.meta.statusCode === 404) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(key: string) {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.client.delete({
|
||||||
|
index: this.index,
|
||||||
|
id: key
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error.meta && error.meta.statusCode !== 404) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async clear() {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
|
||||||
|
await this.client.deleteByQuery({
|
||||||
|
index: this.index,
|
||||||
|
body: {
|
||||||
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
// interfaces
|
// interfaces
|
||||||
import { Client as ElasticClient } from 'elasticsearch';
|
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
||||||
import { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
|
import type { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
// other classes
|
// other classes
|
||||||
import { ElasticScheduler } from './elasticsearch.classes.elasticscheduler';
|
import { ElasticScheduler } from './els.classes.elasticscheduler.js';
|
||||||
import { ElasticIndex } from './elasticsearch.classes.elasticindex';
|
import { ElasticIndex } from './els.classes.elasticindex.js';
|
||||||
|
|
||||||
export interface IStandardLogParams {
|
export interface IStandardLogParams {
|
||||||
message: string;
|
message: string;
|
||||||
@ -14,14 +14,14 @@ export interface IStandardLogParams {
|
|||||||
export interface IElasticSearchConstructorOptions {
|
export interface IElasticSearchConstructorOptions {
|
||||||
indexPrefix: string;
|
indexPrefix: string;
|
||||||
indexRetention: number;
|
indexRetention: number;
|
||||||
port: number;
|
node: string;
|
||||||
domain: string;
|
auth?: {
|
||||||
ssl: boolean;
|
username: string;
|
||||||
user?: string;
|
password: string;
|
||||||
pass?: string;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ElasticSearch<T> {
|
export class ElsSmartlogDestination<T> {
|
||||||
public client: ElasticClient;
|
public client: ElasticClient;
|
||||||
public elasticScheduler = new ElasticScheduler(this);
|
public elasticScheduler = new ElasticScheduler(this);
|
||||||
public elasticIndex: ElasticIndex = new ElasticIndex(this);
|
public elasticIndex: ElasticIndex = new ElasticIndex(this);
|
||||||
@ -35,52 +35,54 @@ export class ElasticSearch<T> {
|
|||||||
*/
|
*/
|
||||||
constructor(optionsArg: IElasticSearchConstructorOptions) {
|
constructor(optionsArg: IElasticSearchConstructorOptions) {
|
||||||
this.client = new ElasticClient({
|
this.client = new ElasticClient({
|
||||||
host: this.computeHostString(optionsArg)
|
node: optionsArg.node,
|
||||||
// log: 'trace'
|
...(optionsArg.auth && { auth: optionsArg.auth }),
|
||||||
});
|
});
|
||||||
this.indexPrefix = optionsArg.indexPrefix;
|
this.indexPrefix = `${optionsArg.indexPrefix}`;
|
||||||
this.indexRetention = optionsArg.indexRetention;
|
this.indexRetention = optionsArg.indexRetention;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* computes the host string from the constructor options
|
|
||||||
* @param optionsArg
|
|
||||||
*/
|
|
||||||
private computeHostString(optionsArg: IElasticSearchConstructorOptions): string {
|
|
||||||
let hostString = `${optionsArg.domain}:${optionsArg.port}`;
|
|
||||||
if (optionsArg.user && optionsArg.pass) {
|
|
||||||
hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`;
|
|
||||||
}
|
|
||||||
if (optionsArg.ssl) {
|
|
||||||
hostString = `https://${hostString}`;
|
|
||||||
} else {
|
|
||||||
hostString = `http://${hostString}`;
|
|
||||||
}
|
|
||||||
return hostString;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()}.${(
|
const indexToUse = `${this.indexPrefix}-${now.toISOString().split('T')[0]}`;
|
||||||
'0' +
|
|
||||||
(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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.elasticIndex.ensureIndex(indexToUse);
|
// Make sure the index is created with a mapping for dynamic JSON
|
||||||
|
const indexExists = await this.client.indices.exists({ index: indexToUse });
|
||||||
|
if (!indexExists.body) {
|
||||||
|
await this.client.indices.create({
|
||||||
|
index: indexToUse,
|
||||||
|
body: {
|
||||||
|
mappings: {
|
||||||
|
properties: {
|
||||||
|
'@timestamp': {
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
logPackageArg: {
|
||||||
|
properties: {
|
||||||
|
payload: {
|
||||||
|
type: 'object',
|
||||||
|
dynamic: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.client.index(
|
this.client.index(
|
||||||
{
|
{
|
||||||
index: indexToUse,
|
index: indexToUse,
|
||||||
type: 'log',
|
|
||||||
body: {
|
body: {
|
||||||
'@timestamp': new Date(logPackageArg.timestamp).toISOString(),
|
'@timestamp': new Date(logPackageArg.timestamp).toISOString(),
|
||||||
...logPackageArg
|
...logPackageArg,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
(error, response) => {
|
(error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -96,9 +98,9 @@ export class ElasticSearch<T> {
|
|||||||
|
|
||||||
get logDestination(): ILogDestination {
|
get logDestination(): ILogDestination {
|
||||||
return {
|
return {
|
||||||
handleLog: (smartlogPackageArg: ILogPackage) => {
|
handleLog: async (smartlogPackageArg: ILogPackage) => {
|
||||||
this.log(smartlogPackageArg);
|
this.log(smartlogPackageArg);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import * as elasticsearch from 'elasticsearch';
|
import * as elasticsearch from '@elastic/elasticsearch';
|
||||||
import * as lik from '@pushrocks/lik';
|
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';
|
@ -1 +1,4 @@
|
|||||||
export * from './elasticsearch.classes.elasticsearch';
|
export * from './els.classes.smartlogdestination.js';
|
||||||
|
export * from './els.classes.fastpush.js';
|
||||||
|
export * from './els.classes.elasticdoc.js';
|
||||||
|
export * from './els.classes.kvstore.js';
|
||||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user