This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
|
||
const { request, createServer } = require('../utils/http'); | ||
const { getTraces } = require('../utils/zipkinQuery'); | ||
|
||
const zipkinHost = '127.0.0.1'; | ||
const zipkinPort = 9411; | ||
const zipkinSampleRate = 1.0; | ||
const serviceName = 'frontend'; | ||
|
||
function waitAndGetTraces() { | ||
return new Promise(resolve => { | ||
setTimeout(() => { // We want to let all background requests going to zipkin complete | ||
resolve(getTraces({ zipkinHost, zipkinPort, serviceName })); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
describe('http requests', () => { | ||
describe('outbound requests', () => { | ||
let server; | ||
let http; | ||
|
||
before(() => { | ||
require('../../')({ | ||
host: zipkinHost, | ||
port: zipkinPort, | ||
sampleRate: zipkinSampleRate, | ||
serviceName | ||
}); | ||
|
||
http = require('http'); | ||
return createServer({ http, port: 3000 }) | ||
.then(createdServer => { | ||
server = createdServer; | ||
}); | ||
}); | ||
after(() => { | ||
if (server) server.close(); | ||
}); | ||
it('should reach zipkin with a simple http request (string options)', () => { | ||
let outgoingTraceId; | ||
return request({ http, options: 'http://localhost:3000' }) | ||
.then(({ request }) => { | ||
const outgoingHeaders = request._headers; | ||
outgoingTraceId = outgoingHeaders['x-b3-traceid']; | ||
}) | ||
.then(waitAndGetTraces) | ||
.then((traces) => { | ||
expect(traces.length > 0).to.be.ok; | ||
expect(traces.some(trace => trace[0].traceId === outgoingTraceId)).to.be.ok; | ||
}); | ||
}); | ||
it('should reach zipkin with a simple http request (object options)', () => { | ||
let outgoingTraceId; | ||
return request({ http, options: { hostname: 'localhost', port: 3000 } }) | ||
.then(({ request }) => { | ||
const outgoingHeaders = request._headers; | ||
outgoingTraceId = outgoingHeaders['x-b3-traceid']; | ||
}) | ||
.then(waitAndGetTraces) | ||
.then((traces) => { | ||
expect(traces.length > 0).to.be.ok; | ||
expect(traces.some(trace => trace[0].traceId === outgoingTraceId)).to.be.ok; | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
module.exports.request = ({ http, options }) => { | ||
return new Promise(resolve => { | ||
http.get(options, (res) => { | ||
resolve({ request: res.req, response: res }); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports.createServer = ({ http, port }) => { | ||
return new Promise((resolve) => { | ||
let server = http.createServer(function(req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end('Hello World\n'); | ||
}); | ||
server.listen(port, function() { | ||
resolve(server); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const request = require('request-promise-native'); | ||
|
||
const url = ({ zipkinHost, zipkinPort }) => `http://${zipkinHost}:${zipkinPort}`; | ||
|
||
module.exports.getTraces = ({ zipkinHost, zipkinPort, serviceName }) => { | ||
const zipkinUrl = url({ zipkinHost, zipkinPort }); | ||
return request({ | ||
url: `${zipkinUrl}/api/v2/traces`, | ||
qs: { | ||
serviceName | ||
}, | ||
json: true | ||
}); | ||
}; | ||
|