Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Transform IP from int32 representation to dot representation #340

Merged
merged 1 commit into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Tracer {
this._tags[constants.JAEGER_CLIENT_VERSION_TAG_KEY] = 'Node-3.14.4';
this._tags[constants.TRACER_HOSTNAME_TAG_KEY] =
this._tags[constants.TRACER_HOSTNAME_TAG_KEY] || os.hostname();
this._tags[constants.PROCESS_IP] = Utils.ipToInt(this._tags[constants.PROCESS_IP] || Utils.myIp());
this._tags[constants.PROCESS_IP] = this._tags[constants.PROCESS_IP] || Utils.myIp();

this._metrics = options.metrics || new Metrics(new NoopMetricFactory());

Expand Down
24 changes: 0 additions & 24 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,6 @@ export default class Utils {
return new Int64(numberValue).toBuffer();
}

/**
* @param {string} ip - a string representation of an ip address.
* @return {number} - a 32-bit number where each byte represents an
* octect of an ip address.
**/
static ipToInt(ip: string): ?number {
let ipl = 0;
let parts = ip.split('.');
if (parts.length != 4) {
return null;
}

for (let i = 0; i < parts.length; i++) {
ipl <<= 8;
ipl += parseInt(parts[i], 10);
}

let signedLimit = 0x7fffffff;
if (ipl > signedLimit) {
return (1 << 32) - ipl;
}
return ipl;
}

/**
* @param {string} input - the input for which leading zeros should be removed.
* @return {string} - returns the input string without leading zeros.
Expand Down
4 changes: 2 additions & 2 deletions test/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('tracer should', () => {
});

it('find the ip and hostname by default', () => {
assert.equal(tracer._tags[constants.PROCESS_IP], Utils.ipToInt(Utils.myIp()));
assert.equal(tracer._tags[constants.PROCESS_IP], Utils.myIp());
assert.equal(tracer._tags[constants.TRACER_HOSTNAME_TAG_KEY], os.hostname());
});

Expand All @@ -74,7 +74,7 @@ describe('tracer should', () => {
tags: mytags,
});

assert.equal(mytracer._tags[constants.PROCESS_IP], Utils.ipToInt('10.0.0.1'));
assert.equal(mytracer._tags[constants.PROCESS_IP], '10.0.0.1');
assert.equal(mytracer._tags[constants.TRACER_HOSTNAME_TAG_KEY], '10.0.0.1.internal');
});

Expand Down
14 changes: 0 additions & 14 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ import Utils from '../src/util.js';
import combinations from './lib/combinations.js';

describe('utils', () => {
describe('ipToInt', () => {
it('should convert malformed IP to null', () => {
assert.isNotOk(Utils.ipToInt('127.0'));
});

it('should convert an ip less than 2^32 to an unsigned number', () => {
assert.equal((127 << 24) | 1, Utils.ipToInt('127.0.0.1'));
});

it('should convert an ip greater than 2^32 to a negative number', () => {
assert.equal(-1, Utils.ipToInt('255.255.255.255'));
});
});

describe('removeLeadingZeros', () => {
it('should leave single 0 digit intact', () => {
assert.equal('0', Utils.removeLeadingZeros('0'));
Expand Down