Skip to content

Commit 17b7c1b

Browse files
Merge pull request #20 from ExpediaDotCom/integration-tests
Adding integration tests using docker and haystack-agent
2 parents 62aef7b + 945e1e2 commit 17b7c1b

11 files changed

Lines changed: 230 additions & 90 deletions

File tree

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ sudo: required
22

33
language: node_js
44

5+
services:
6+
- docker
7+
58
node_js:
69
- "6"
710

@@ -11,12 +14,8 @@ env:
1114
- TAG=${TRAVIS_TAG}
1215
- SHA=${TRAVIS_COMMIT}
1316

14-
cache:
15-
directories:
16-
- node_modules
17-
1817
script:
19-
- make build
18+
- make build integration_tests
2019

2120
before_deploy:
2221
- make prepare_publish

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ prepare_publish:
2222

2323
.PHONY: test
2424
test:
25-
./node_modules/mocha/bin/mocha -r ./node_modules/ts-node/register tests/**/*.ts
25+
./node_modules/mocha/bin/mocha -r ./node_modules/ts-node/register tests/unit/**/*.ts
26+
27+
.PHONY: integration_tests
28+
integration_tests:
29+
docker-compose -f integration-tests/docker-compose.yml -p sandbox up -d
30+
sleep 15
31+
docker run -it \
32+
--rm \
33+
--network=sandbox_default \
34+
-v $(PWD):/ws \
35+
-w /ws \
36+
node:6-alpine \
37+
/bin/sh -c 'mkdir -p ws2 && cp -a src tests package.json tsconfig.json ws2/ && cd ws2 && npm i && ./node_modules/mocha/bin/mocha -r ./node_modules/ts-node/register tests/integration/**/*.ts'
38+
docker-compose -f integration-tests/docker-compose.yml -p sandbox stop
2639

2740
.PHONY: compile
2841
compile:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
services:
3+
haystack_agent:
4+
image: expediadotcom/haystack-agent:0.1
5+
depends_on:
6+
- zookeeper
7+
- kafkasvc
8+
environment:
9+
haystack_env_agents_spans_port: 35000
10+
haystack_env_agents_spans_dispatchers_kafka_bootstrap_servers: "kafkasvc:9092"
11+
ports:
12+
- "35000:35000"
13+
entrypoint:
14+
- /bin/sh
15+
- -c
16+
- 'sleep 10 && java -jar /app/bin/haystack-agent.jar --config-provider file --file-path /app/bin/dev.conf'
17+
zookeeper:
18+
image: wurstmeister/zookeeper
19+
ports:
20+
- "2181:2181"
21+
kafkasvc:
22+
image: wurstmeister/kafka:2.11-1.1.1
23+
depends_on:
24+
- zookeeper
25+
environment:
26+
KAFKA_ADVERTISED_HOST_NAME: "kafkasvc"
27+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
28+
volumes:
29+
- /var/run/docker.sock:/var/run/docker.sock
30+
ports:
31+
- "9092:9092"

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"type": "git",
1414
"url": "git://github.com/ExpediaDotCom/haystack-client-node.git"
1515
},
16-
"scripts": {
17-
"lint": "tslint -t msbuild -c tslint.json 'src/**/*.ts'"
18-
},
1916
"contributors": [
2017
"Haystack <haystack@expedia.com>"
2118
],
@@ -29,6 +26,8 @@
2926
"@types/node": "7.0.12",
3027
"@types/chai": "3.4.35",
3128
"@types/mocha": "2.2.40",
29+
"@types/kafka-node": "2.0.7",
30+
"kafka-node": "2.6.1",
3231
"chai": "^3.5.0",
3332
"grpc-tools": "1.6.6",
3433
"mocha": "^2.5.3",

scripts/version.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const pkginfo = require('npm-registry-package-info');
22
const semver = require('semver');
3+
const { resolve } = require('path');
34
const fs = require('fs');
45

5-
66
const moduleName = 'haystack-client';
77

88
const opts = {
@@ -23,8 +23,7 @@ pkginfo(opts, (error, data) => {
2323
if (semver.lte(releaseVersion, currentVersion)) {
2424
throw new Error(`Current haystack-client on npm registry has greater than or equal new release version ${releaseVersion}. Check your git tag version`);
2525
}
26-
const rawPackageJson = fs.readFileSync('package.json');
27-
const packageJson = JSON.parse(rawPackageJson);
26+
const packageJson = require(resolve(process.cwd(), 'package.json'));
2827
packageJson.version = releaseVersion;
2928
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, ' '));
3029
});

src/dispatchers/dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ import Span from '../span';
1818

1919
export interface Dispatcher {
2020
name(): string;
21-
dispatch(span: Span, callback: (error) => void): void;
21+
dispatch(span: Span, callback?: (error) => void): void;
2222
close(callback: () => void): void;
2323
}

src/dispatchers/remote.ts

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import * as grpc from 'grpc';
18-
const messages = require('../proto_idl_codegen/span_pb');
1918
const services = require('../proto_idl_codegen/agent/spanAgent_grpc_pb');
2019
import {Dispatcher} from './dispatcher';
2120
import Span from '../span';
@@ -39,7 +38,7 @@ export default class RemoteDispatcher implements Dispatcher {
3938
}
4039

4140
dispatch(span: Span, callback: (error) => void): void {
42-
const proto = this._convertToProtoSpan(span);
41+
const proto = Utils.convertToProtoSpan(span);
4342
this._client.dispatch(proto, (err, response) => {
4443
if (err) {
4544
if (this._logger) {
@@ -59,73 +58,6 @@ export default class RemoteDispatcher implements Dispatcher {
5958
});
6059
}
6160

62-
private _convertToProtoSpan(span: Span): any {
63-
const protoSpan = new messages.Span();
64-
protoSpan.setServicename(span.serviceName());
65-
protoSpan.setOperationname(span.operationName());
66-
protoSpan.setTraceid(span.context().traceId);
67-
protoSpan.setSpanid(span.context().spanId);
68-
protoSpan.setParentspanid(span.context().parentSpanId);
69-
protoSpan.setStarttime(span.startTime());
70-
protoSpan.setDuration(span.duration());
71-
72-
const protoSpanTags = [];
73-
74-
const tags = span.tags();
75-
for (const k in tags) {
76-
if (tags.hasOwnProperty(k)) {
77-
protoSpanTags.push(RemoteDispatcher._createProtoTag(k, tags[k]));
78-
}
79-
}
80-
81-
protoSpan.setTagsList(protoSpanTags);
82-
83-
const protoSpanLogs = [];
84-
span.logs().forEach(log => {
85-
const protoLog = new messages.Log();
86-
const protoLogTags = [];
87-
const kvPairs = log.keyValuePairs;
88-
for (const k in kvPairs) {
89-
if (kvPairs.hasOwnProperty(k)) {
90-
protoLogTags.push(RemoteDispatcher._createProtoTag(k, kvPairs[k]));
91-
}
92-
}
93-
protoLog.setTimestamp(log.timestamp);
94-
protoLog.setFieldsList(protoLogTags);
95-
protoSpanLogs.push(protoLog);
96-
});
97-
98-
protoSpan.setLogsList(protoSpanLogs);
99-
return protoSpan;
100-
}
101-
102-
private static _createProtoTag(key: string, value: any): any {
103-
const protoTag = new messages.Tag();
104-
protoTag.setKey(key);
105-
106-
const tagValue = value;
107-
if (typeof tagValue === 'number') {
108-
if (Utils.isFloatType(tagValue)) {
109-
protoTag.setVdouble(tagValue);
110-
protoTag.setType(messages.Tag.TagType.DOUBLE);
111-
} else {
112-
protoTag.setVlong(tagValue);
113-
protoTag.setType(messages.Tag.TagType.LONG);
114-
}
115-
} else if (typeof tagValue === 'boolean') {
116-
protoTag.setVbool(tagValue);
117-
protoTag.setType(messages.Tag.TagType.BOOL);
118-
} else if (typeof tagValue === 'string') {
119-
protoTag.setVstr(tagValue);
120-
protoTag.setType(messages.Tag.TagType.STRING);
121-
} else {
122-
protoTag.setVbytes(tagValue);
123-
protoTag.setType(messages.Tag.TagType.BINARY);
124-
}
125-
126-
return protoTag;
127-
}
128-
12961
close(callback: () => void): void {
13062
grpc.closeClient(this._client);
13163
if (callback) {

src/utils.ts

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import uuidv4 = require('uuid/v4');
17+
import * as uuid from 'uuid';
18+
import Span from './span';
19+
const messages = require('./proto_idl_codegen/span_pb');
1820

1921
export default class Utils {
2022
static randomUUID(): string {
21-
return uuidv4();
23+
return uuid.v4();
2224
}
2325

2426
static assign(origObject, key, value): any {
@@ -57,4 +59,71 @@ export default class Utils {
5759
static isFloatType(value: number): boolean {
5860
return (value % 1 !== 0);
5961
}
62+
63+
static convertToProtoSpan(span: Span): any {
64+
const protoSpan = new messages.Span();
65+
protoSpan.setServicename(span.serviceName());
66+
protoSpan.setOperationname(span.operationName());
67+
protoSpan.setTraceid(span.context().traceId);
68+
protoSpan.setSpanid(span.context().spanId);
69+
protoSpan.setParentspanid(span.context().parentSpanId);
70+
protoSpan.setStarttime(span.startTime());
71+
protoSpan.setDuration(span.duration());
72+
73+
const protoSpanTags = [];
74+
75+
const tags = span.tags();
76+
for (const k in tags) {
77+
if (tags.hasOwnProperty(k)) {
78+
protoSpanTags.push(this._createProtoTag(k, tags[k]));
79+
}
80+
}
81+
82+
protoSpan.setTagsList(protoSpanTags);
83+
84+
const protoSpanLogs = [];
85+
span.logs().forEach(log => {
86+
const protoLog = new messages.Log();
87+
const protoLogTags = [];
88+
const kvPairs = log.keyValuePairs;
89+
for (const k in kvPairs) {
90+
if (kvPairs.hasOwnProperty(k)) {
91+
protoLogTags.push(this._createProtoTag(k, kvPairs[k]));
92+
}
93+
}
94+
protoLog.setTimestamp(log.timestamp);
95+
protoLog.setFieldsList(protoLogTags);
96+
protoSpanLogs.push(protoLog);
97+
});
98+
99+
protoSpan.setLogsList(protoSpanLogs);
100+
return protoSpan;
101+
}
102+
103+
private static _createProtoTag(key: string, value: any): any {
104+
const protoTag = new messages.Tag();
105+
protoTag.setKey(key);
106+
107+
const tagValue = value;
108+
if (typeof tagValue === 'number') {
109+
if (Utils.isFloatType(tagValue)) {
110+
protoTag.setVdouble(tagValue);
111+
protoTag.setType(messages.Tag.TagType.DOUBLE);
112+
} else {
113+
protoTag.setVlong(tagValue);
114+
protoTag.setType(messages.Tag.TagType.LONG);
115+
}
116+
} else if (typeof tagValue === 'boolean') {
117+
protoTag.setVbool(tagValue);
118+
protoTag.setType(messages.Tag.TagType.BOOL);
119+
} else if (typeof tagValue === 'string') {
120+
protoTag.setVstr(tagValue);
121+
protoTag.setType(messages.Tag.TagType.STRING);
122+
} else {
123+
protoTag.setVbytes(tagValue);
124+
protoTag.setType(messages.Tag.TagType.BINARY);
125+
}
126+
127+
return protoTag;
128+
}
60129
}

0 commit comments

Comments
 (0)