Compare commits

...

44 Commits

Author SHA1 Message Date
2b0003546a 1.0.42 2023-07-05 15:31:01 +02:00
60617f2fca fix(core): update 2023-07-05 15:31:00 +02:00
9c767d07e4 1.0.41 2023-07-05 10:26:00 +02:00
f3aa94dcb7 fix(core): update 2023-07-05 10:25:59 +02:00
a0be0edd9d 1.0.40 2023-07-05 10:22:53 +02:00
ad24ba2f5d fix(core): update 2023-07-05 10:22:53 +02:00
b0cf4bb27f 1.0.39 2023-07-05 09:38:43 +02:00
fd29ceab80 fix(core): update 2023-07-05 09:38:43 +02:00
bcca434a24 1.0.38 2023-07-04 13:57:55 +02:00
d4a9ad8f67 fix(core): update 2023-07-04 13:57:55 +02:00
d4c7c33668 1.0.37 2023-07-04 10:50:19 +02:00
8340257b00 fix(core): update 2023-07-04 10:50:18 +02:00
32265e83f3 1.0.36 2023-07-04 10:13:15 +02:00
e2df11cea2 fix(core): update 2023-07-04 10:13:15 +02:00
2719ba28f6 1.0.35 2023-07-04 09:59:58 +02:00
6d78a7ba0c fix(core): update 2023-07-04 09:59:58 +02:00
5897c6e7de 1.0.34 2023-07-04 09:46:04 +02:00
20369614a2 fix(core): update 2023-07-04 09:46:04 +02:00
7ceaf694fe 1.0.33 2023-07-04 09:33:19 +02:00
391c6bd45d fix(core): update 2023-07-04 09:33:18 +02:00
1a702071c6 1.0.32 2023-07-04 09:13:45 +02:00
0fe2f6a4ae fix(core): update 2023-07-04 09:13:44 +02:00
20d04413c9 1.0.31 2023-07-04 09:13:15 +02:00
e56439e9f4 fix(core): update 2023-07-04 09:13:14 +02:00
c9a9434cd9 1.0.30 2019-11-03 00:51:18 +01:00
5d98dd9089 fix(core): update 2019-11-03 00:51:18 +01:00
2d635fdf7c 1.0.29 2019-11-03 00:49:35 +01:00
1dbf3724d0 fix(core): update 2019-11-03 00:49:35 +01:00
cc7eb8c139 1.0.28 2019-11-03 00:47:19 +01:00
0e01ecbd1a fix(core): update 2019-11-03 00:47:18 +01:00
2d21b40a76 1.0.27 2019-11-02 01:42:04 +01:00
2d1a5cdc50 fix(core): update 2019-11-02 01:42:03 +01:00
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
22 changed files with 5092 additions and 1363 deletions

View 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

View 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
View File

@ -1,5 +1,20 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,131 +1,119 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
mirror:
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci git mirror
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- docker
- notpriv
- lossless
- docker
allow_failure: true
snyk:
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- docker
- notpriv
- lossless
- docker
allow_failure: true
# ====================
# 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:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
testSTABLE:
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--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]
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
@ -133,15 +121,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
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
- public
allow_failure: true

4
.snyk
View File

@ -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
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -2,5 +2,16 @@
"npmci": {
"npmGlobalTools": [],
"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"
}
}
}

1128
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,48 @@
{
"name": "@mojoio/elasticsearch",
"version": "1.0.20",
"name": "@apiclient.xyz/elasticsearch",
"version": "1.0.42",
"private": false,
"description": "log to elasticsearch in a kibana compatible format",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"format": "(gitzone format)",
"build": "(tsbuild)"
"build": "(tsbuild --allowimplicitany)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.1.13",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^2.0.2",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.2",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.42",
"@gitzone/tstest": "^1.0.74",
"@pushrocks/qenv": "^5.0.2",
"@pushrocks/tapbundle": "^5.0.8",
"@types/node": "^20.3.3"
},
"dependencies": {
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartlog-interfaces": "^2.0.2",
"@pushrocks/smartpromise": "^2.0.5",
"@types/elasticsearch": "^5.0.28",
"elasticsearch": "^15.2.0"
}
"@elastic/elasticsearch": "7.17.11-patch.1",
"@pushrocks/lik": "^6.0.2",
"@pushrocks/smartdelay": "^3.0.1",
"@pushrocks/smartlog-interfaces": "^3.0.0",
"@pushrocks/smartpromise": "^4.0.2",
"@pushrocks/smarttime": "^4.0.1"
},
"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

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,2 @@
vars:
- ELK_DOMAIN
- ELK_PORT
- ELK_USER
- ELK_PASS
required:

View File

@ -1,26 +1,26 @@
# elasticlog
# @mojoio/elasticsearch
log to elasticsearch in a kibana compatible format
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/elasticlog)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/elasticlog)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/elasticlog)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/elasticlog/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/elasticsearch)
* [gitlab.com (source)](https://gitlab.com/mojoio/elasticsearch)
* [github.com (source mirror)](https://github.com/mojoio/elasticsearch)
* [docs (typedoc)](https://mojoio.gitlab.io/elasticsearch/)
## Status for master
[![build status](https://GitLab.com/pushrocks/elasticlog/badges/master/build.svg)](https://GitLab.com/pushrocks/elasticlog/commits/master)
[![coverage report](https://GitLab.com/pushrocks/elasticlog/badges/master/coverage.svg)](https://GitLab.com/pushrocks/elasticlog/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/elasticlog.svg)](https://www.npmjs.com/package/elasticlog)
[![Dependency Status](https://david-dm.org/pushrocks/elasticlog.svg)](https://david-dm.org/pushrocks/elasticlog)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/elasticlog/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/elasticlog/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/elasticlog/badges/code.svg)](https://www.bithound.io/github/pushrocks/elasticlog)
[![Known Vulnerabilities](https://snyk.io/test/npm/elasticlog/badge.svg)](https://snyk.io/test/npm/elasticlog)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/elasticsearch/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/elasticsearch/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/elasticsearch)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/elasticsearch)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@mojoio/elasticsearch)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@mojoio/elasticsearch)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@mojoio/elasticsearch)](https://lossless.cloud)
## 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](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)

View File

@ -1,24 +1,22 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
import * as elasticsearch from '../ts/index';
const testQenv = new Qenv('./', './.nogit/');
import * as elasticsearch from '../ts/index.js';
let testElasticLog: elasticsearch.ElasticSearch<any>;
tap.test('first test', async () => {
testElasticLog = new elasticsearch.ElasticSearch({
domain: process.env.ELK_DOMAIN,
port: parseInt(process.env.ELK_PORT, 10),
ssl: true,
user: process.env.ELK_USER,
pass: process.env.ELK_PASS
indexPrefix: 'testprefix',
indexRetention: 7,
node: 'http://localhost:9200',
user: 'elastic',
pass: 'YourPassword'
});
expect(testElasticLog).to.be.instanceOf(elasticsearch.ElasticSearch);
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
});
tap.test('should send a message to Elasticsearch', async () => {
testElasticLog.log({
await testElasticLog.log({
timestamp: Date.now(),
type: 'increment',
level: 'info',
@ -28,9 +26,10 @@ tap.test('should send a message to Elasticsearch', async () => {
containerName: 'testcontainer',
environment: 'test',
runtime: 'node',
zone: 'ship.zone'
zone: 'ship.zone',
},
message: 'hi, this is a testMessage'
message: 'GET https://myroute.to.a.cool.destination/sorare?hello=there',
correlation: null,
});
});

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@apiclient.xyz/elasticsearch',
version: '1.0.42',
description: 'log to elasticsearch in a kibana compatible format'
}

View File

@ -1,6 +1,6 @@
import * as plugins from './elasticsearch.plugins';
import { ElasticSearch } from './elasticsearch.classes.elasticsearch';
import { ILogPackage } from '@pushrocks/smartlog-interfaces';
import * as plugins from './elasticsearch.plugins.js';
import { ElasticSearch } from './elasticsearch.classes.elasticsearch.js';
import { type ILogPackage } from '@pushrocks/smartlog-interfaces';
import { Stringmap } from '@pushrocks/lik';
@ -12,34 +12,75 @@ export class ElasticIndex {
this.elasticSearchRef = elasticSearchInstanceArg;
}
public async ensureIndex(indexArg: string) {
const done = plugins.smartpromise.defer();
if(this.stringmap.checkString(indexArg)) {
public async ensureIndex(prefixArg: string, indexNameArg: string) {
if (this.stringmap.checkString(indexNameArg)) {
return;
}
this.elasticSearchRef.client.cat.indices({
const responseArg = await this.elasticSearchRef.client.cat.indices({
format: 'json',
bytes: 'm'
}, async (err, response: any[]) => {
// 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();
bytes: 'm',
}).catch(err => {
console.log(err);
});
await done.promise;
if (!responseArg) {
throw new Error('Could not get valid response from elastic search');
}
// lets delete indexes that violate the retention
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,
});
}
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);
});
}
}
}
}

View File

@ -1,4 +1,4 @@
import { ElasticSearch, IStandardLogParams } from './elasticsearch.classes.elasticsearch';
import { ElasticSearch, type IStandardLogParams } from './elasticsearch.classes.elasticsearch.js';
export class ElasticScheduler {
elasticSearchRef: ElasticSearch<any>;

View File

@ -1,20 +1,20 @@
// interfaces
import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
import { Client as ElasticClient } from '@elastic/elasticsearch';
import type { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
// other classes
import { ElasticScheduler } from './elasticsearch.classes.elasticscheduler';
import { ElasticIndex } from './elasticsearch.classes.elasticindex';
import { ElasticScheduler } from './elasticsearch.classes.elasticscheduler.js';
import { ElasticIndex } from './elasticsearch.classes.elasticindex.js';
export interface IStandardLogParams {
message: string;
severity: string;
}
export interface IElasticLogConstructorOptions {
port: number;
domain: string;
ssl: boolean;
export interface IElasticSearchConstructorOptions {
indexPrefix: string;
indexRetention: number;
node: string;
user?: string;
pass?: string;
}
@ -24,56 +24,43 @@ export class ElasticSearch<T> {
public elasticScheduler = new ElasticScheduler(this);
public elasticIndex: ElasticIndex = new ElasticIndex(this);
public indexPrefix: string;
public indexRetention: number;
/**
* sets up an instance of Elastic log
* @param optionsArg
*/
constructor(optionsArg: IElasticLogConstructorOptions) {
constructor(optionsArg: IElasticSearchConstructorOptions) {
this.client = new ElasticClient({
host: this.computeHostString(optionsArg),
log: 'trace'
node: optionsArg.node,
auth: {
username: optionsArg.user,
password: optionsArg.pass,
}
});
}
/**
* computes the host string from the constructor options
* @param optionsArg
*/
private computeHostString(optionsArg: IElasticLogConstructorOptions): 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;
this.indexPrefix = optionsArg.indexPrefix;
this.indexRetention = optionsArg.indexRetention;
}
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
const now = new Date();
const indexToUse = `smartlog-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(-2)}.${(
'0' + now.getDate()
).slice(-2)}`;
const indexToUse = `${this.indexPrefix}-${now.toISOString().split('T')[0]}`;
if (this.elasticScheduler.docsScheduled && !scheduleOverwrite) {
this.elasticScheduler.scheduleDoc(logPackageArg);
return;
}
await this.elasticIndex.ensureIndex(indexToUse);
const response = await this.elasticIndex.ensureIndex(this.indexPrefix, indexToUse);
console.log(response);
this.client.index(
{
index: indexToUse,
type: 'log',
body: {
'@timestamp': new Date(logPackageArg.timestamp).toISOString(),
...logPackageArg
}
...logPackageArg,
},
},
(error, response) => {
if (error) {
@ -81,17 +68,17 @@ export class ElasticSearch<T> {
console.log(error);
this.elasticScheduler.addFailedDoc(logPackageArg);
} else {
console.log(`ElasticLog: ${logPackageArg.message}`);
// console.log(`ElasticLog: ${logPackageArg.message}`);
}
}
);
}
get logDestination (): ILogDestination {
get logDestination(): ILogDestination {
return {
handleLog: (smartlogPackageArg: ILogPackage) => {
handleLog: async (smartlogPackageArg: ILogPackage) => {
this.log(smartlogPackageArg);
}
}
},
};
}
}

View File

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

View File

@ -1 +1 @@
export * from './elasticsearch.classes.elasticsearch';
export * from './elasticsearch.classes.elasticsearch.js';

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}

View File

@ -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"
}