Skip to content

Commit

Permalink
rename kadira to monti
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoventurini committed Oct 26, 2023
1 parent 66fec98 commit fbd3475
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 102 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Monti APM Core

This is a fork of [kadira-core](https://github.com/kadirahq/kadira-core).
This is a fork of [monti-core](https://github.com/montihq/monti-core).

Handle core functionalities of Monti APM such as

Expand All @@ -12,5 +12,5 @@ Handle core functionalities of Monti APM such as
You can debug what's happening inside the Monti APM transport by exposing following environment variable:

```
export `DEBUG=kadira-core:transport`
export `DEBUG=monti-apm-core:transport`
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test:dist": "mocha 'dist/**/*.test.js' --exit",
"test": "mocha src/**/*.test.js --require=ts-node/register/transpile-only --exit",
"test:watch": "nodemon --exec 'npm run test' -e js,ts --watch src",
"test:debug": "cross-env DEBUG=kadira-core:* npm run test:watch",
"test:debug": "cross-env DEBUG=monti-apm-core:* npm run test:watch",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default class Clock {
}

getTime() {
// current time on Kadira server
// current time on Monti server
return this._clientTS() + this._diff;
}

fixTime(timestamp: number) {
// `timestamp` on Kadira server
// `timestamp` on Monti server
return timestamp + this._diff;
}

Expand Down
114 changes: 57 additions & 57 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from 'assert';
import { afterEach, beforeEach, describe, it } from 'mocha';
import server from './tests/server';
import Kadira from './index';
import Monti from './index';
import { ByPassRetryError } from './retry';
import { Readable } from 'stream';
import { expect } from 'chai';
import { hostname } from 'os';

describe('kadira', function () {
describe('monti', function () {
const endpoint = 'http://localhost:8000';
const validAuth = { appId: 'test-app-id', appSecret: 'test-app-secret' };
const validOpts = Object.assign({ endpoint }, validAuth);
Expand All @@ -29,47 +29,47 @@ describe('kadira', function () {
describe('connect', function () {
it('should throw with wrong info', async function () {
let erred = false;
const kadira = new Kadira(invldOpts);
const monti = new Monti(invldOpts);

try {
await kadira.connect();
await monti.connect();
} catch (e) {
assert.strictEqual(e instanceof ByPassRetryError, true);
erred = true;
}

assert(erred);
kadira.disconnect();
monti.disconnect();
});

it('should connect with correct info', async function () {
const kadira = new Kadira(validOpts);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(validOpts);
await monti.connect();
monti.disconnect();
});

it('should sync the diff value', async function () {
const kadira = new Kadira(validOpts);
await kadira.connect();
kadira.disconnect();
assert(inRange(kadira._clock._diff, -1100, -900));
const monti = new Monti(validOpts);
await monti.connect();
monti.disconnect();
assert(inRange(monti._clock._diff, -1100, -900));
});
});

describe('sendData', function () {
it('should send data to the server', async function () {
const options = Object.assign({}, validOpts, { dataFlushInterval: 100 });
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();

await kadira.sendData({
await monti.sendData({
test1: [{ a: 'b' }, { c: 'd' }],
test2: [{ e: 'f' }],
});

assert.deepStrictEqual(server.getData(), {
host: kadira._options.hostname,
host: monti._options.hostname,
test1: [{ a: 'b' }, { c: 'd' }],
test2: [{ e: 'f' }],
});
Expand All @@ -80,11 +80,11 @@ describe('kadira', function () {
const dataString = Buffer.alloc(30000000, '0').toString();

const options = Object.assign({}, validOpts, { dataFlushInterval: 100 });
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();

await kadira.sendData({ content: dataString });
await monti.sendData({ content: dataString });

expect(server.getData()).to.deep.equal({
content: dataString,
Expand All @@ -97,11 +97,11 @@ describe('kadira', function () {
dataFlushInterval: 100,
agentVersion: '1.5.0',
});
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();

await kadira.sendData({});
await monti.sendData({});
assert.strictEqual(server.getHeaders()['monti-agent-version'], '1.5.0');
});

Expand All @@ -110,12 +110,12 @@ describe('kadira', function () {
dataFlushInterval: 100,
agentVersion: '1.5.0',
});
const kadira = new Kadira(options);
const monti = new Monti(options);

const a = {};
a.a = a;

kadira.sendData(a).catch((e) => {
monti.sendData(a).catch((e) => {
assert.strictEqual(e.message.includes('circular structure'), true);
done();
});
Expand All @@ -125,24 +125,24 @@ describe('kadira', function () {
describe('get', function () {
it('should make get request', async function () {
const options = Object.assign({}, validOpts);
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();

const result = await kadira.get('/_test/text');
const result = await monti.get('/_test/text');
assert.strictEqual(result, 'hello-world');
});

it('should allow disabling retries', async function () {
this.timeout(20000);
const options = Object.assign({}, validOpts);
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();
server.setCount(0);

try {
await kadira.get('/_test/e5xx', { noRetry: true });
await monti.get('/_test/e5xx', { noRetry: true });
} catch (e) {
assert.strictEqual(server.getCount(), 1);
assert.strictEqual(e.message, 'Request failed: 500');
Expand All @@ -155,13 +155,13 @@ describe('kadira', function () {
it('should allow disabling retries for network errors', async function () {
this.timeout(20000);
const options = Object.assign({}, validOpts);
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();
server.setCount(0);

try {
await kadira.get('/_test/network-err', { noRetry: true });
await monti.get('/_test/network-err', { noRetry: true });
} catch (e) {
assert.strictEqual(server.getCount(), 1);
assert.strictEqual(e.message, 'socket hang up');
Expand All @@ -175,68 +175,68 @@ describe('kadira', function () {
describe('sendStream', function () {
it('should send stream to the server', async function () {
const options = Object.assign({}, validOpts);
const kadira = new Kadira(options);
await kadira.connect();
kadira.disconnect();
const monti = new Monti(options);
await monti.connect();
monti.disconnect();

const s = new Readable();
s.push('content');
s.push(null);

await kadira.sendStream('/stream', s);
await monti.sendStream('/stream', s);

assert.strictEqual(server.getData(), 'content');
});
});

describe('updateJob', function () {
it('should send data to the server', async function () {
const kadira = new Kadira(validOpts);
await kadira.connect();
await kadira.updateJob('job-0', { foo: 'bar' });
const monti = new Monti(validOpts);
await monti.connect();
await monti.updateJob('job-0', { foo: 'bar' });

assert.deepStrictEqual(server.getJobs(), {
action: 'set',
params: { id: 'job-0', foo: 'bar' },
});

kadira.disconnect();
monti.disconnect();
});
});

describe('getJob', function () {
it('should send data to the server', async function () {
const kadira = new Kadira(validOpts);
await kadira.connect();
const monti = new Monti(validOpts);
await monti.connect();

const res = await kadira.getJob('job-0');
const res = await monti.getJob('job-0');
assert.deepStrictEqual(res, { aa: 10 });
assert.deepStrictEqual(server.getJobs(), {
action: 'get',
params: { id: 'job-0' },
});

kadira.disconnect();
monti.disconnect();
});
});

describe('_checkAuth', () => {
describe('with correct login info', () => {
it('should just return', async () => {
const kadira = new Kadira(validOpts);
await kadira._checkAuth();
kadira.disconnect();
const monti = new Monti(validOpts);
await monti._checkAuth();
monti.disconnect();
});
});

describe('with bad login info', () => {
it('should throw an error', (done) => {
const kadira = new Kadira(invldOpts);
kadira._checkAuth().catch((err) => {
const monti = new Monti(invldOpts);
monti._checkAuth().catch((err) => {
assert.strictEqual(err.message, 'Unauthorized');
done();
});
kadira.disconnect();
monti.disconnect();
});
});
});
Expand Down
18 changes: 8 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { hostname } from 'os';
import EventEmitter2 from 'eventemitter2';
import { persistentConnectWebSocket } from './utils/websocket-utils';

const logger = debug('kadira-core:transport');
const jobLogger = debug('kadira-core:jobs');
const logger = debug('monti-core:transport');
const jobLogger = debug('monti-core:jobs');

export type Job = {
id: string;
[key: string]: any;
};

export type KadiraOptions = {
export type MontiOptions = {
appId: string;
appSecret: string;
agentVersion: string;
Expand All @@ -44,7 +44,7 @@ const defaultOptions = {
appId: '',
appSecret: '',
agentVersion: 'unknown',
endpoint: 'https://enginex.kadira.io',
endpoint: 'https://enginex.monti.io',
hostname: hostname(),
clockSyncInterval: 1000 * 60,
dataFlushInterval: 1000 * 10,
Expand All @@ -57,22 +57,22 @@ const defaultOptions = {
export class Monti extends EventEmitter2 {
_supportedFeatures = SupportedFeatures;
_allowedFeatures: Record<string, boolean> = {};
_options: KadiraOptions;
_options: MontiOptions;
_headers: Record<string, string> = {};
_clock: Clock;
_clockSyncInterval: NodeJS.Timeout | null;
_disconnectWebSocket: (() => void) | null = null;
_disconnected = false;

constructor(_options?: Partial<KadiraOptions>) {
constructor(_options?: Partial<MontiOptions>) {
super();

this._options = Object.assign({}, defaultOptions, _options);
this._headers = {
'content-type': ContentType.JSON,
accepts: ContentType.JSON,
'kadira-app-id': this._options.appId,
'kadira-app-secret': this._options.appSecret,
'monti-app-id': this._options.appId,
'monti-app-secret': this._options.appSecret,
'monti-agent-version': this._options.agentVersion,
'monti-agent-hostname': this._options.hostname,
};
Expand Down Expand Up @@ -283,8 +283,6 @@ export class Monti extends EventEmitter2 {
}
}

export const Kadira = Monti;

export default Monti;

export * from './constants';
4 changes: 2 additions & 2 deletions src/tests/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default {

function authenticate(req) {
return (
req.headers['kadira-app-id'] === 'test-app-id' &&
req.headers['kadira-app-secret'] === 'test-app-secret'
req.headers['monti-app-id'] === 'test-app-id' &&
req.headers['monti-app-secret'] === 'test-app-secret'
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import debug from 'debug';
import { Feature, HttpMethod, SupportedFeatures } from '../constants';

const logger = debug('kadira-core:transport');
const logger = debug('monti-apm-core:transport');

export function getAxiosConfig(params: AxiosRequestConfig): AxiosRequestConfig {
return {
Expand Down
Loading

0 comments on commit fbd3475

Please sign in to comment.