Compare commits

...

30 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
22 changed files with 5061 additions and 2059 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/ .nogit/
node_modules/
# artifacts
coverage/ coverage/
public/ public/
pages/ pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

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

1805
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,48 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@apiclient.xyz/elasticsearch",
"version": "1.0.27", "version": "1.0.42",
"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.1.17", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.42",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.74",
"@pushrocks/qenv": "^4.0.6", "@pushrocks/qenv": "^5.0.2",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^5.0.8",
"@types/node": "^12.12.5", "@types/node": "^20.3.3"
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.11", "@elastic/elasticsearch": "7.17.11-patch.1",
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/lik": "^6.0.2",
"@pushrocks/smartlog-interfaces": "^2.0.9", "@pushrocks/smartdelay": "^3.0.1",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartlog-interfaces": "^3.0.0",
"@pushrocks/smarttime": "^3.0.12", "@pushrocks/smartpromise": "^4.0.2",
"@types/elasticsearch": "^5.0.35", "@pushrocks/smarttime": "^4.0.1"
"elasticsearch": "^16.5.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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -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)
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/elasticlog) * [gitlab.com (source)](https://gitlab.com/mojoio/elasticsearch)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/elasticlog) * [github.com (source mirror)](https://github.com/mojoio/elasticsearch)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/elasticlog) * [docs (typedoc)](https://mojoio.gitlab.io/elasticsearch/)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/elasticlog/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/elasticlog/badges/master/build.svg)](https://GitLab.com/pushrocks/elasticlog/commits/master) Status Category | Status Badge
[![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) GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/elasticsearch/badges/master/pipeline.svg)](https://lossless.cloud)
[![Dependency Status](https://david-dm.org/pushrocks/elasticlog.svg)](https://david-dm.org/pushrocks/elasticlog) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/elasticsearch/badges/master/coverage.svg)](https://lossless.cloud)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/elasticlog/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/elasticlog/master/dependencies/npm) npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/elasticsearch)](https://lossless.cloud)
[![bitHound Code](https://www.bithound.io/github/pushrocks/elasticlog/badges/code.svg)](https://www.bithound.io/github/pushrocks/elasticlog) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/elasticsearch)](https://lossless.cloud)
[![Known Vulnerabilities](https://snyk.io/test/npm/elasticlog/badge.svg)](https://snyk.io/test/npm/elasticlog) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) 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 ## 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![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 { expect, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv'; import { Qenv } from '@pushrocks/qenv';
import * as elasticsearch from '../ts/index'; import * as elasticsearch from '../ts/index.js';
const testQenv = new Qenv('./', './.nogit/');
let testElasticLog: elasticsearch.ElasticSearch<any>; 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', indexPrefix: 'testprefix',
indexRetention: 7, indexRetention: 7,
domain: testQenv.getEnvVarOnDemand('ELK_DOMAIN'), node: 'http://localhost:9200',
port: parseInt(testQenv.getEnvVarOnDemand('ELK_PORT'), 10), user: 'elastic',
ssl: true pass: 'YourPassword'
}); });
expect(testElasticLog).to.be.instanceOf(elasticsearch.ElasticSearch); expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
}); });
tap.test('should send a message to Elasticsearch', async () => { tap.test('should send a message to Elasticsearch', async () => {
testElasticLog.log({ await testElasticLog.log({
timestamp: Date.now(), timestamp: Date.now(),
type: 'increment', type: 'increment',
level: 'info', level: 'info',
@ -28,9 +26,10 @@ tap.test('should send a message to Elasticsearch', async () => {
containerName: 'testcontainer', containerName: 'testcontainer',
environment: 'test', environment: 'test',
runtime: 'node', 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 * as plugins from './elasticsearch.plugins.js';
import { ElasticSearch } from './elasticsearch.classes.elasticsearch'; import { ElasticSearch } from './elasticsearch.classes.elasticsearch.js';
import { ILogPackage } from '@pushrocks/smartlog-interfaces'; import { type ILogPackage } from '@pushrocks/smartlog-interfaces';
import { Stringmap } from '@pushrocks/lik'; import { Stringmap } from '@pushrocks/lik';
@ -12,94 +12,74 @@ export class ElasticIndex {
this.elasticSearchRef = elasticSearchInstanceArg; this.elasticSearchRef = elasticSearchInstanceArg;
} }
public async ensureIndex(indexArg: string) { public async ensureIndex(prefixArg: string, indexNameArg: string) {
const done = plugins.smartpromise.defer(); if (this.stringmap.checkString(indexNameArg)) {
if (this.stringmap.checkString(indexArg)) {
done.resolve();
return; return;
} }
this.elasticSearchRef.client.cat.indices( const responseArg = await this.elasticSearchRef.client.cat.indices({
{ format: 'json',
format: 'json', bytes: 'm',
bytes: 'm' }).catch(err => {
}, console.log(err);
async (err, responseArg: any[]) => { });
if(err) {
console.log(err);
return;
}
// lets delete indexes that violate the retention if (!responseArg) {
if(Array.isArray(responseArg)) { throw new Error('Could not get valid response from elastic search');
const filteredIndices = responseArg.filter(indexObjectArg => { }
return indexObjectArg.index.startsWith('smartlog');
});
const filteredIndexNames = filteredIndices.map(indexObjectArg => {
return indexObjectArg.index;
});
this.deleteOldIndices(filteredIndexNames);
}
let index = null; // 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);
}
if(Array.isArray(responseArg)) { let index = null;
index = responseArg.find(indexObject => {
return indexObject.index === indexArg;
});
}
if (!index) { if (Array.isArray(responseArg.body)) {
const done2 = plugins.smartpromise.defer(); index = responseArg.body.find((indexItemArg) => {
this.elasticSearchRef.client.indices.create( return indexItemArg.index === indexNameArg;
{ });
}
waitForActiveShards: '1', if (!index) {
index: indexArg await this.createNewIndex(indexNameArg);
}, }
(error, response) => { this.stringmap.addString(indexNameArg);
// console.lof(response) return index;
done2.resolve();
}
);
await done2.promise;
}
this.stringmap.addString(indexArg);
done.resolve();
}
);
await done.promise;
} }
public createNewIndex(indexNameArg: string) { public async createNewIndex(indexNameArg: string) {
const response = await this.elasticSearchRef.client.indices.create({
wait_for_active_shards: '1',
index: indexNameArg,
});
} }
public async deleteOldIndices(indicesArray: string[]) { public async deleteOldIndices(prefixArg: string, indicesArray: string[]) {
const todayAsUnix: number = Date.now(); const todayAsUnix: number = Date.now();
const rententionPeriodAsUnix: number = plugins.smarttime.units.days( const rententionPeriodAsUnix: number = plugins.smarttime.units.days(
this.elasticSearchRef.indexRetention this.elasticSearchRef.indexRetention
); );
for (const indexName of indicesArray) { for (const indexName of indicesArray) {
const regexResult = /^smartlog-([0-9]*)\.([0-9]*)\.([0-9]*)$/.exec(indexName); 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( const dateAsUnix: number = new Date(
`${regexResult[1]}-${regexResult[2]}-${regexResult[3]}` `${regexResult[1]}-${regexResult[2]}-${regexResult[3]}`
).getTime(); ).getTime();
if (todayAsUnix - rententionPeriodAsUnix > dateAsUnix) { if (todayAsUnix - rententionPeriodAsUnix > dateAsUnix) {
console.log(`found old index ${indexName}`); console.log(`found old index ${indexName}`);
const done2 = plugins.smartpromise.defer(); const response = await this.elasticSearchRef.client.indices.delete(
this.elasticSearchRef.client.indices.delete(
{ {
index: indexName index: indexName,
}, }).catch(err => {
(err2, response2) => { console.log(err);
if (err2) { });
console.log(err2);
}
console.log(`deleted ${indexName}`);
done2.resolve();
}
);
await done2.promise;
} }
} }
} }

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 { export class ElasticScheduler {
elasticSearchRef: ElasticSearch<any>; elasticSearchRef: ElasticSearch<any>;

View File

@ -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 './elasticsearch.classes.elasticscheduler.js';
import { ElasticIndex } from './elasticsearch.classes.elasticindex'; import { ElasticIndex } from './elasticsearch.classes.elasticindex.js';
export interface IStandardLogParams { export interface IStandardLogParams {
message: string; message: string;
@ -14,9 +14,7 @@ export interface IStandardLogParams {
export interface IElasticSearchConstructorOptions { export interface IElasticSearchConstructorOptions {
indexPrefix: string; indexPrefix: string;
indexRetention: number; indexRetention: number;
port: number; node: string;
domain: string;
ssl: boolean;
user?: string; user?: string;
pass?: string; pass?: string;
} }
@ -35,53 +33,34 @@ 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' auth: {
username: optionsArg.user,
password: optionsArg.pass,
}
}); });
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}`;
}
console.log(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); const response = await this.elasticIndex.ensureIndex(this.indexPrefix, indexToUse);
console.log(response);
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) {
@ -97,9 +76,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);
} },
}; };
} }
} }

View File

@ -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';

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