Compare commits

..

6 Commits

Author SHA1 Message Date
williamlardier 29cc14c7e5
progress 2022-11-24 10:44:31 +01:00
williamlardier 11cd9ed40e
ARTESCA-6419: standardize exports 2 2022-11-23 17:49:43 +01:00
williamlardier b080ddd542
ARTESCA-6419: standardize exports 2022-11-23 17:46:23 +01:00
williamlardier f4a7c3a968
ARTESCA-6419: create base abstraction layers for http agent 2022-11-23 16:19:38 +01:00
williamlardier ce3264dd63
ARTESCA-6419: add github actions files for tests and release 2022-11-23 16:15:15 +01:00
williamlardier e5c2fa6cdb
ARTESCA-6419: initialize repository 2022-11-23 16:11:55 +01:00
20 changed files with 1638 additions and 179 deletions

View File

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

View File

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

23
.eslintrc.json Normal file
View File

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

View File

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

View File

View File

@ -1,16 +1,3 @@
# HttpAgent # Arsenal-Networking
HttpAgent is a library on top of the native `http` and `https` NodeJS Agents Common utilities for Scality S3 project components networking.
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.

View File

@ -1,18 +0,0 @@
# 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
View File

@ -1,29 +0,0 @@
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);
}
}

View File

@ -1,11 +0,0 @@
/* 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;

10
index.ts Normal file
View File

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

View File

@ -1,17 +0,0 @@
/**
* 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;

6
lib/config/default.ts Normal file
View File

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

View File

@ -1,28 +0,0 @@
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;

39
lib/http-agent.ts Normal file
View File

@ -0,0 +1,39 @@
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,
});
}
}

View File

@ -1,28 +0,0 @@
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;

39
lib/https-agent.ts Normal file
View File

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

22
tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"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 Normal file

File diff suppressed because it is too large Load Diff