Compare commits

..

42 Commits

Author SHA1 Message Date
Vitaliy Filippov 32b843aaf3 Change git dependency URLs 2024-07-21 17:37:36 +03:00
William 66e97ab935
Merge pull request #9 from scality/improvement/ARSNN-2-fixup-declarations
Improvement/arsnn 2 fixup declarations
2022-12-14 17:14:27 +01:00
williamlardier 8425d23e04
ARSNN-2: bump project version 2022-12-14 17:12:36 +01:00
williamlardier 2e3d13c5b9
ARSNN-2: fixups for declarations 2022-12-14 17:12:18 +01:00
William ec4e28f050
Merge pull request #8 from scality/improvement/ARSNN-2-convert-project-to-JS
Improvement/arsnn 2 convert project to js
2022-12-14 14:58:52 +01:00
williamlardier 435c7436d0
ARSNN-2: bump project to 1.0.5 2022-12-14 14:12:33 +01:00
williamlardier aae50a9096
ARSNN-2: export declarations 2022-12-14 14:12:30 +01:00
williamlardier 1881146b28
ARSNN-2: cleanups for eslint and exports 2022-12-14 11:44:18 +01:00
williamlardier 6c600cd02f
ARSNN-2: convert files to JS and update environment 2022-12-14 11:33:12 +01:00
williamlardier 72108aed4f
ARSNN-2: remove TS files 2022-12-14 11:32:45 +01:00
William e14a16f988
Merge pull request #7 from scality/improvement/ARSNN-1-fix-agentkeepalive-import
Improvement/arsnn 1 fix agentkeepalive import
2022-12-13 08:31:11 +01:00
williamlardier bc5fc17097
ARSNN-1: bump project version 2022-12-13 08:29:08 +01:00
williamlardier 0a56b2a48c
ARSNN-1: fix import for https base class 2022-12-13 08:28:45 +01:00
William 0330b36bb3
Merge pull request #6 from scality/improvement/ARSNN-1-export-default-configuration-for-maxsockets
Improvement/arsnn 1 export default configuration for maxsockets
2022-12-13 08:11:34 +01:00
williamlardier 179d43d73a
ARSNN-1: bump project version 2022-12-12 22:58:42 +01:00
williamlardier 9304a78cc4
ARSNN-1: fixup class name 2022-12-12 22:58:39 +01:00
williamlardier eb40166fd8
ARSNN-1: rename files and types 2022-12-12 22:53:33 +01:00
williamlardier 71e1a487a5
ARSNN-1: use agentkeepalive as the base class 2022-12-12 22:51:03 +01:00
williamlardier 7c6c9127cb
ARSNN-1: introduce agentkeepalive 2022-12-12 22:50:42 +01:00
williamlardier 93938413e9
ARSNN-1: export configuration in index 2022-12-12 22:09:42 +01:00
williamlardier a3af7cdd1e
ARSNN-1: use exported configuration 2022-12-12 22:09:23 +01:00
williamlardier fed919ae16
ARSNN-1: export common configuration 2022-12-12 22:09:10 +01:00
William 676a70e102
Merge pull request #5 from scality/improvement/ARTESCA-6420-better-builds
Improvement/artesca 6420 better builds
2022-12-07 18:04:37 +01:00
williamlardier 481e44308b
ARTESCA-6420: bump project version 2022-12-07 14:55:17 +01:00
williamlardier 4235b98de8
ARTESCA-6420: add empty npmignore 2022-12-07 14:55:16 +01:00
williamlardier d0b147fe85
ARTESCA-6420: improve module builds 2022-12-07 14:55:16 +01:00
williamlardier a4f419ebfa
ARTESCA-6420: more consistent class names 2022-12-07 14:55:12 +01:00
William fed06b3abf
Merge pull request #4 from scality/improvement/ARTESCA-6420-use-httpagent-repo-name
ARTESCA-6420: replace arsenal-networking with httpagent
2022-12-07 10:11:25 +01:00
williamlardier 264d776838
ARTESCA-6420: bump project version 2022-12-07 09:58:59 +01:00
williamlardier 1ef5ac9705
ARTESCA-6420: replace arsenal-networking with httpagent 2022-12-07 09:58:11 +01:00
William 34e20e72c8
Merge pull request #3 from scality/improvement/ARTESCA-6420-add-release-workflow
ARTESCA-6420: add releases workflow
2022-12-05 16:31:21 +01:00
williamlardier 38607a83b3
ARTESCA-6420: add release documentation 2022-12-05 16:28:48 +01:00
williamlardier 5f688379e7
ARTESCA-6420: specify engine version 2022-12-05 16:28:44 +01:00
williamlardier ad70fdf5b0
ARTESCA-6420: remove v prefix from the tagged release in precheck 2022-12-05 16:28:29 +01:00
williamlardier 8ea438271b
ARTESCA-6420: remove v prefix from the tagged release 2022-12-05 16:28:29 +01:00
williamlardier d1da0f6575
ARTESCA-6420: add releases workflow 2022-12-05 16:28:28 +01:00
William 5a3d96b49c
Merge pull request #2 from scality/improvement/ARTESCA-6419-initial-http-agent-wrapper
Improvement/artesca 6419 initial http agent wrapper
2022-12-05 16:27:20 +01:00
williamlardier c09ac9f116
ARTESCA-6419: update project README 2022-12-05 16:24:35 +01:00
williamlardier 51fcaab601
ARTESCA-6419: add tests workflows for build and syntax checks 2022-12-05 16:24:35 +01:00
williamlardier a21e1b7b42
ARTESCA-6419: implement base http(s) agents and export 2022-12-05 16:24:32 +01:00
williamlardier 1f939d7d96
ARTESCA-6419: package.json with dev dependencies 2022-11-24 11:06:31 +01:00
williamlardier 76dc08740d
ARTESCA-6419: initialize project devdeps configuration 2022-11-24 11:06:28 +01:00
20 changed files with 179 additions and 1638 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
index.d.ts

15
.eslintrc.cjs Normal file
View File

@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
},
};

View File

@ -1,23 +0,0 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": ["build/**/*.js", "build/**/*.d.ts"],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

View File

@ -12,7 +12,7 @@ jobs:
name: Verify if tag is valid
runs-on: ubuntu-latest
steps:
- name: Checkout CTST repository
- name: Checkout httpagent repository
uses: 'actions/checkout@v3'
with:
ref: ${{ github.ref }}
@ -23,7 +23,7 @@ jobs:
- name: 'Check if tag was already created'
shell: bash
run: >
git show-ref --tags v${{ github.event.inputs.tag }} --quiet \
git show-ref --tags ${{ github.event.inputs.tag }} --quiet \
&& exit 1 || exit 0
release:
@ -38,6 +38,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Release ${{ github.event.inputs.tag }}
tag_name: v${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
generate_release_notes: true
target_commitish: ${{ github.sha }}

View File

@ -32,5 +32,4 @@ jobs:
run: yarn install --frozen-lockfile
- name: run lint
run: yarn run eslint
- name: run build
run: yarn build

0
.npmignore Normal file
View File

View File

@ -1,3 +1,16 @@
# Arsenal-Networking
# HttpAgent
Common utilities for Scality S3 project components networking.
HttpAgent is a library on top of the native `http` and `https` NodeJS Agents
to enforce consistent, still configurable networking configuration for Scality
micro services.
What HttpAgent is:
- A wrapper enforcing, by default, both `keepAlive` and `maxSockets` options.
- A centralized way of handling Http(s) Agents, while supporting consistent
environment variables across components.
- A library that can be extended with more standard configurations.
What HttpAgent is not:
- An all-in-one library for networking-related code.

18
docs/RELEASE.md Normal file
View File

@ -0,0 +1,18 @@
# HttpAgent
## How to release ARSNN
To release a ARSNN version:
- Bump the project version in `package.json` in a PR and merge it.
- When the PR is merged, trigger the
[Release Workflow](https://github.com/scality/httpagent/actions/workflows/release.yaml)
via the workflow dispatch function. Use the `development/*` branch.
- You MUST fill the form with a tag. The new version you enter MUST be a valid
[SemVer](https://semver.org) version, matching with your `package.json`
version.
- The workflow will dynamically tag the project and generate a release
changelog.

29
index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
import HttpAgent, { HttpsAgent } from 'agentkeepalive';
import { HttpsOptions, HttpOptions } from 'agentkeepalive';
declare namespace http {
export interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}
export class Agent extends HttpAgent {
constructor(opts?: HttpOptions, config?: clientConfigurationDefault);
}
}
declare namespace https {
export interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}
export class Agent extends HttpsAgent {
constructor(opts?: HttpsOptions, config?: clientConfigurationDefault);
}
}

11
index.js Normal file
View File

@ -0,0 +1,11 @@
/* eslint-disable global-require */
exports.http = {
Agent: require('./lib/http-agent').default,
};
exports.https = {
Agent: require('./lib/https-agent').default,
};
exports.AgentConfiguration = require('./lib/config/agentConfiguration').default;

View File

@ -1,10 +0,0 @@
import httpAgent from "./lib/http-agent";
import httpsAgent from "./lib/https-agent";
export const http = {
Agent: httpAgent,
};
export const https = {
Agent: httpsAgent,
};

View File

@ -0,0 +1,17 @@
/**
* The maximum socket configuration defaults to 50.
*/
const maxSocketsNumber = Number(process.env.MAX_SOCKETS) || 50;
/**
* The default configuration for the maxSocket profile.
* The goal is to enforce a `maxSockets` property to properly
* handle load.
*/
const agentConfiguration = {
keepAlive: true,
maxSockets: maxSocketsNumber,
maxFreeSockets: maxSocketsNumber,
};
exports.default = agentConfiguration;

View File

@ -1,6 +0,0 @@
export default interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}

28
lib/http-agent.js Normal file
View File

@ -0,0 +1,28 @@
const HttpAgent = require('agentkeepalive');
const agentConfiguration = require('./config/agentConfiguration');
/**
* @class AgentHttp
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
class AgentHttp extends HttpAgent {
/**
* Constructor for the AgentHttp class
*
* @param opts - Custom HTTP Agent options
* @param config - user-defined default configuration to apply
*/
constructor(opts, config = {
maxSockets: true,
}) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({ ...opts, ...defaultConfigurations });
}
}
exports.default = AgentHttp;

View File

@ -1,39 +0,0 @@
import * as http from 'http';
import clientConfigurationDefault from './config/default';
/**
* @class ClientHttp
* Abstracts the native http.Agent class to enforce common
* networking configuration across components.
*/
export default class ClientHttp extends http.Agent {
/**
* The maximum socket configuration defaults to 50.
*/
private static maxSocketsConfiguration = Number(process.env.MAX_SOCKETS) || 50;
/**
* Constructor for the ClientHttp class
*
* @param opts - Custom HTTP Agent options
* @param config - user-defined default configuration du apply
*/
constructor(
opts?: http.AgentOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
const defaultConfigurations: http.AgentOptions = {};
if (config.maxSockets) {
defaultConfigurations.keepAlive = true;
defaultConfigurations.maxSockets = ClientHttp.maxSocketsConfiguration;
defaultConfigurations.maxFreeSockets = ClientHttp.maxSocketsConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}

28
lib/https-agent.js Normal file
View File

@ -0,0 +1,28 @@
const { HttpsAgent } = require('agentkeepalive');
const agentConfiguration = require('./config/agentConfiguration');
/**
* @class AgentHttps
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
class AgentHttps extends HttpsAgent {
/**
* Constructor for the AgentHttps class
*
* @param opts - Custom HTTPs Agent options
* @param config - user-defined default configuration to apply
*/
constructor(opts, config = {
maxSockets: true,
}) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({ ...opts, ...defaultConfigurations });
}
}
exports.default = AgentHttps;

View File

@ -1,39 +0,0 @@
import * as https from 'https';
import clientConfigurationDefault from './config/default';
/**
* @class ClientHttps
* Abstracts the native https.Agent class to enforce common
* networking configuration across components.
*/
export default class ClientHttps extends https.Agent {
/**
* The maximum socket configuration defaults to 50.
*/
private static maxSocketsConfiguration = Number(process.env.MAX_SOCKETS) || 50;
/**
* Constructor for the ClientHttps class
*
* @param opts - Custom HTTPs Agent options
* @param config - user-defined default configuration du apply
*/
constructor(
opts?: https.AgentOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
const defaultConfigurations: https.AgentOptions = {};
if (config.maxSockets) {
defaultConfigurations.keepAlive = true;
defaultConfigurations.maxSockets = ClientHttps.maxSocketsConfiguration;
defaultConfigurations.maxFreeSockets = ClientHttps.maxSocketsConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}

View File

@ -1,33 +1,30 @@
{
"name": "arsenal-networking",
"version": "1.0.0",
"name": "httpagent",
"version": "1.0.6",
"engines": {
"node": ">=16"
},
"description": "A utility library for networking",
"main": "build/index.js",
"repository": "git@github.com:scality/arsenal-networking.git",
"main": "index.js",
"repository": "git@github.com:scality/httpagent.git",
"author": "Scality Inc.",
"license": "Apache-2.0",
"scripts": {
"build": "tsc --build tsconfig.json",
"format": "prettier --write \"**/*.{ts,tsx,css,html}\" ",
"prepare": "yarn build || true",
"eslint": "eslint ./ --ext .js,.ts,.tsx",
"eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix",
"eslint-init": "eslint --init",
"lint": "eslint ./ --ext .js,.ts,.tsx --format visualstudio --no-color --max-warnings 10 --report-unused-disable-directives"
"eslint-init": "eslint --init"
},
"dependencies": {
"@types/node": "^18.11.9"
"agentkeepalive": "^4.2.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-scality": "git+https://github.com/scality/Guidelines#8.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-config-scality": "git+https://git.yourcmc.ru/vitalif/zenko-eslint-config-scality.git",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.0",
"typescript": "^4.9.3"
"prettier": "^2.8.0"
}
}

View File

@ -1,22 +0,0 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": false,
"outDir": "build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"declaration": true,
"noImplicitAny": false,
"noEmitOnError": false,
"sourceMap": true,
"declarationMap": true
},
"include": ["index.ts", "lib"],
"exclude": ["node_modules/*"],
"compileOnSave": true
}

1476
yarn.lock

File diff suppressed because it is too large Load Diff