Skip to content

Commit

Permalink
chore: support v8
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Feb 21, 2023
1 parent 0bb8e35 commit aeffbd7
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ shared: &shared
key: v{{ .Environment.CACHE_VERSION }}-prisma-app-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/collector/test/tracing/database/prisma/package-lock.json" }}

elasticsearch: &elasticsearch
- image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
- image: docker.elastic.co/elasticsearch/elasticsearch:8.6.1
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms500m -Xmx500m"
- xpack.security.enabled=false

kafka: &kafka
- image: wurstmeister/kafka:2.12-2.2.1
Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ services:
# discovery.type: single-node
# ES_JAVA_OPTS: "-Xms500m -Xmx500m"

# Elasticsearch 7.6
# Elasticsearch 7 compatible with client v7
# elasticsearch:
# image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
# ports:
# - 9200:9200
# environment:
# discovery.type: single-node
# ES_JAVA_OPTS: "-Xms500m -Xmx500m"

# Elasticsearch 8 compatible with client v7 & v8
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
image: docker.elastic.co/elasticsearch/elasticsearch:8.6.1
ports:
- 9200:9200
environment:
discovery.type: single-node
ES_JAVA_OPTS: "-Xms500m -Xmx500m"
xpack.security.enabled: 'false'

# Kafka test will sometimes fail because Zookeeper won't start due to
# java.io.IOException: Unable to create data directory /opt/zookeeper-3.4.9/data/version-2, which seems to be a known issue:
Expand Down
95 changes: 95 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@elastic/elasticsearch": "^8.6.0",
"@elastic/elasticsearch-v7.17.0": "npm:@elastic/[email protected]",
"@elastic/elasticsearch-v7.9.0": "npm:@elastic/[email protected]",
"@google-cloud/pubsub": "3.3.0",
"@google-cloud/storage": "^5.16.1",
Expand Down
161 changes: 115 additions & 46 deletions packages/collector/test/tracing/database/elasticsearch_modern/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const port = require('../../../test_util/app-port')();

const app = express();
const logPrefix = `Elasticsearch ${process.env.ELASTIC_VERSION} (Modern Client) (${process.pid}):\t`;
const isLatest = process.env.ELASTIC_VERSION === 'latest';

if (process.env.WITH_STDOUT) {
app.use(morgan(`${logPrefix}:method :url :status`));
Expand All @@ -32,24 +33,52 @@ const client = new Client({
node: `http://${process.env.ELASTICSEARCH}`
});

// v7 & v8 have a different return value
const commonReturnValue = response => {
if (response.body) return response;

return {
body: response
};
};

app.get('/', (req, res) => {
res.sendStatus(200);
});

app.get('/get', (req, res) => {
client.get(
{
index: req.query.index || 'modern_index',
id: req.query.id
},
{},
(error, response) => {
// Execute another traced call to verify that we keep the tracing context.
request(`http://127.0.0.1:${agentPort}`).then(() => {
res.json({ error, response });
// v8 dropped cb support
if (isLatest) {
client
.get({
index: req.query.index || 'modern_index',
id: req.query.id
})
.then(response => {
request(`http://127.0.0.1:${agentPort}`).then(() => {
res.json({ response: commonReturnValue(response) });
});
})
.catch(err => {
request(`http://127.0.0.1:${agentPort}`).then(() => {
res.json({ error: err });
});
});
}
);
} else {
client.get(
{
index: req.query.index || 'modern_index',
id: req.query.id
},
{},
(error, response) => {
// Execute another traced call to verify that we keep the tracing context.
request(`http://127.0.0.1:${agentPort}`).then(() => {
res.json({ error, response: commonReturnValue(response) });
});
}
);
}
});

app.get('/search', (req, res) => {
Expand All @@ -65,7 +94,7 @@ app.get('/search', (req, res) => {
return request(`http://127.0.0.1:${agentPort}`);
})
.then(() => {
res.json({ response: searchResponse });
res.json({ response: commonReturnValue(searchResponse) });
})
.catch(error => {
res.json({ error });
Expand All @@ -77,52 +106,89 @@ app.get('/mget1', (req, res) => {
if (!Array.isArray(ids) || ids.length < 2) {
return res.status(400).json({ error: 'You need to provide an array of at least two document IDs.' });
}
client.mget(
{
body: {
docs: [
{ _index: req.query.index || 'modern_index', _id: ids[0] },
{ _index: req.query.index || 'modern_index', _id: ids[1] }
]
}
},
(error, response) => {
if (error) {
res.json({ error });
} else {
res.json({ response });

if (isLatest) {
client
.mget({
body: {
docs: [
{ _index: req.query.index || 'modern_index', _id: ids[0] },
{ _index: req.query.index || 'modern_index', _id: ids[1] }
]
}
})
.then(response => {
res.json({ response: commonReturnValue(response) });
})
.catch(err => {
res.json({ error: err });
});
} else {
client.mget(
{
body: {
docs: [
{ _index: req.query.index || 'modern_index', _id: ids[0] },
{ _index: req.query.index || 'modern_index', _id: ids[1] }
]
}
},
(error, response) => {
if (error) {
res.json({ error });
} else {
res.json({ response: commonReturnValue(response) });
}
}
}
);
);
}
});

app.get('/mget2', (req, res) => {
const ids = req.query.id;
if (!Array.isArray(ids) || ids.length < 2) {
return res.status(400).json({ error: 'You need to provide an array of at least two document IDs.' });
}
client.mget(
{
index: req.query.index || 'modern_index',
body: {
ids
}
},
(error, response) => {
if (error) {
res.json({ error });
} else {
res.json({ response });

if (isLatest) {
client
.mget({
index: req.query.index || 'modern_index',
body: {
ids
}
})
.then(response => {
res.json({ response: commonReturnValue(response) });
})
.catch(err => {
res.json({ error: err });
});
} else {
client.mget(
{
index: req.query.index || 'modern_index',
body: {
ids
}
},
(error, response) => {
if (error) {
res.json({ error });
} else {
res.json({ response });
}
}
}
);
);
}
});

app.get('/msearch', (req, res) => {
const queryStrings = req.query.q;
if (!Array.isArray(queryStrings) || queryStrings.length < 2) {
return res.status(400).json({ error: 'You need to provide an array of at least two query params' });
}

const query = {
body: [
{ index: req.query.index || 'modern_index' },
Expand All @@ -131,9 +197,10 @@ app.get('/msearch', (req, res) => {
{ query: { query_string: { query: req.query.q[1] } } }
]
};

client.msearch(query).then(
response => {
res.json({ response });
res.json({ response: commonReturnValue(response) });
},
error => {
res.json({ error });
Expand All @@ -142,6 +209,8 @@ app.get('/msearch', (req, res) => {
});

app.post('/index', (req, res) => {
const ignoreKey = isLatest ? 'ignore_unavailable' : 'ignoreUnavailable';

client
.index({
index: req.query.index || 'modern_index',
Expand All @@ -151,10 +220,10 @@ app.post('/index', (req, res) => {
client.indices
.refresh({
index: '_all',
ignoreUnavailable: true
[ignoreKey]: true
})
.then(
() => response,
() => commonReturnValue(response),
error => {
log('Index refresh failed.', error);
throw error;
Expand Down
Loading

0 comments on commit aeffbd7

Please sign in to comment.