-
Notifications
You must be signed in to change notification settings - Fork 63
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
10 changed files
with
305 additions
and
8,548 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
/*! | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import * as http from 'http'; | ||
import agent from '../../../src'; | ||
|
||
agent.start({ | ||
serviceName: 'client', | ||
maxBufferSize: 1000, | ||
}) | ||
|
||
const server = http.createServer(async (req, res) => { | ||
const q = 'queue'; | ||
|
||
await new Promise((resolve, reject) => { | ||
require('amqplib/callback_api').connect(`amqp://${process.env.RABBITMQ_HOST}`, (err: any, conn: any) => { | ||
conn.createChannel((err: any, ch: any) => { | ||
ch.assertQueue(q, {durable: false}); | ||
ch.consume(q, (msg: any) => { | ||
ch.ack(msg); | ||
ch.close(() => conn.close(() => { | ||
res.end('done'); | ||
resolve(null); | ||
})); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
server.listen(5001, () => console.info('Listening on port 5001...')); |
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,80 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
version: "2.1" | ||
|
||
services: | ||
collector: | ||
extends: | ||
file: ../common/base-compose.yml | ||
service: collector | ||
networks: | ||
- traveling-light | ||
|
||
rabbitmq: | ||
container_name: rabbitmq | ||
ports: | ||
- 5672:5672 | ||
healthcheck: | ||
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/5672"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 120 | ||
image: "rabbitmq:latest" | ||
networks: | ||
- traveling-light | ||
|
||
producer: | ||
extends: | ||
file: ../common/base-compose.yml | ||
service: agent | ||
ports: | ||
- 5000:5000 | ||
environment: | ||
RABBITMQ_HOST: rabbitmq | ||
healthcheck: | ||
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/5000"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 120 | ||
entrypoint: | ||
["bash", "-c", "npx ts-node /app/tests/plugins/amqplib/producer.ts"] | ||
depends_on: | ||
rabbitmq: | ||
condition: service_healthy | ||
|
||
consumer: | ||
extends: | ||
file: ../common/base-compose.yml | ||
service: agent | ||
ports: | ||
- 5001:5001 | ||
environment: | ||
RABBITMQ_HOST: rabbitmq | ||
healthcheck: | ||
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/5001"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 120 | ||
entrypoint: | ||
["bash", "-c", "npx ts-node /app/tests/plugins/amqplib/consumer.ts"] | ||
depends_on: | ||
rabbitmq: | ||
condition: service_healthy | ||
|
||
networks: | ||
traveling-light: |
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,74 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
segmentItems: | ||
- serviceName: server | ||
segmentSize: 1 | ||
segments: | ||
- segmentId: not null | ||
spans: | ||
- operationName: RabbitMQ//queue/Producer | ||
operationId: 0 | ||
parentSpanId: 0 | ||
spanId: 1 | ||
spanLayer: MQ | ||
tags: | ||
- { key: mq.broker, value: amqp://192.168.16.3:5672 } | ||
- { key: mq.queue, value: queue } | ||
startTime: gt 0 | ||
endTime: gt 0 | ||
componentId: 52 | ||
spanType: Exit | ||
peer: 192.168.16.3:5672 | ||
skipAnalysis: false | ||
- operationName: /producer | ||
operationId: 0 | ||
parentSpanId: -1 | ||
spanId: 0 | ||
spanLayer: Http | ||
tags: | ||
- { key: http.url, value: 'http://localhost:5000/producer' } | ||
- { key: http.method, value: GET } | ||
- { key: http.status.code, value: '200' } | ||
- { key: http.status.msg, value: OK } | ||
startTime: gt 0 | ||
endTime: gt 0 | ||
componentId: 49 | ||
spanType: Entry | ||
peer: not null | ||
skipAnalysis: false | ||
- serviceName: client | ||
segmentSize: 1 | ||
segments: | ||
- segmentId: not null | ||
spans: | ||
- operationName: RabbitMQ//queue/Consumer | ||
operationId: 0 | ||
parentSpanId: -1 | ||
spanId: 0 | ||
spanLayer: MQ | ||
tags: | ||
- { key: mq.broker, value: 'amqp://192.168.16.3:5672' } | ||
- { key: mq.queue, value: queue } | ||
- { key: http.status.code, value: '200' } # this is RabbitMQ Entry inheriting HTTP server Entry, should not happen, need to fix | ||
- { key: http.status.msg, value: OK } | ||
startTime: gt 0 | ||
endTime: gt 0 | ||
componentId: 53 | ||
spanType: Entry | ||
peer: not null | ||
skipAnalysis: false |
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,45 @@ | ||
/*! | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import * as http from 'http'; | ||
import agent from '../../../src'; | ||
|
||
agent.start({ | ||
serviceName: 'server', | ||
maxBufferSize: 1000, | ||
}); | ||
|
||
const server = http.createServer(async (req, res) => { | ||
const q = 'queue'; | ||
|
||
await new Promise((resolve, reject) => { | ||
require('amqplib/callback_api').connect(`amqp://${process.env.RABBITMQ_HOST}`, (err: any, conn: any) => { | ||
conn.createChannel((err: any, ch: any) => { | ||
ch.assertQueue(q, {durable: false}); | ||
ch.sendToQueue(q, Buffer.from('something callback to do')); | ||
ch.close(() => conn.close(() => { | ||
res.end('done'); | ||
resolve(null); | ||
})); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
server.listen(5000, () => console.info('Listening on port 5000...')); |
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,57 @@ | ||
/*! | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import { DockerComposeEnvironment, StartedDockerComposeEnvironment, Wait } from 'testcontainers'; | ||
import axios from 'axios'; | ||
import waitForExpect from 'wait-for-expect'; | ||
import { promises as fs } from 'fs'; | ||
|
||
const rootDir = path.resolve(__dirname); | ||
|
||
describe('plugin tests', () => { | ||
let compose: StartedDockerComposeEnvironment; | ||
|
||
beforeAll(async () => { | ||
compose = await new DockerComposeEnvironment(rootDir, 'docker-compose.yml') | ||
.withWaitStrategy('rabbitmq', Wait.forHealthCheck()) | ||
.up(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await compose.down(); | ||
}); | ||
|
||
it(__filename, async () => { | ||
await waitForExpect(async () => expect((await axios.get('http://localhost:5000/producer')).status).toBe(200)); | ||
await waitForExpect(async () => expect((await axios.get('http://localhost:5001/consumer')).status).toBe(200)); | ||
|
||
const expectedData = await fs.readFile(path.join(rootDir, 'expected.data.yaml'), 'utf8'); | ||
|
||
try { | ||
await waitForExpect(async () => | ||
expect((await axios.post('http://localhost:12800/dataValidate', expectedData)).status).toBe(200), | ||
); | ||
} catch (e) { | ||
const actualData = (await axios.get('http://localhost:12800/receiveData')).data; | ||
console.info({ actualData }); | ||
throw e; | ||
} | ||
}); | ||
}); |
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