Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
feat(one-app-runner): add option to load jaeger all-in-one (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Apr 1, 2024
2 parents 3db3a67 + e6503ca commit bb5a6be
Show file tree
Hide file tree
Showing 32 changed files with 1,445 additions and 1,009 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@
"no-console": 0, // CLI's are allowed to use console
"unicorn/no-process-exit": 0, // CLI's are allowed to exit
"unicorn/prefer-spread": 0 // Spread is not always semantically identical
}
},
"overrides": [
{
"files": ["**/__tests__/**", "**/__mocks__/**", "**/__fixtures__/**", "**/*.spec.js"],
"extends": "amex/test",
"rules": {
"no-console": 0, // CLI's are allowed to use console
"unicorn/no-process-exit": 0, // CLI's are allowed to exit
"unicorn/prefer-spread": 0 // Spread is not always semantically identical
}
}
]
}
1 change: 1 addition & 0 deletions jest.cjs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
'!**/build/**',
'packages/*/lib/**',
'!packages/*/bin/**',
'!packages/*/__fixtures__/**',
'!packages/*/test-utils.js',
'!packages/*/test-results/**',
],
Expand Down
8 changes: 0 additions & 8 deletions packages/eslint-plugin-one-app/.eslintrc.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/one-app-locale-bundler/__tests__/.eslintrc.json

This file was deleted.

105 changes: 67 additions & 38 deletions packages/one-app-runner/README.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions packages/one-app-runner/__fixtures__/jaeger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed 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.
*/

const { v4: uuidv4 } = require('uuid');

const mockTraceId = () => uuidv4().replace(/-/g, '').slice(0, 32);
const mockSpanId = () => uuidv4().replace(/-/g, '').slice(0, 16);
const mockTraceResponse = (traceId) => `00-${traceId || mockTraceId()}-${mockSpanId()}-01`;

const mockJaegerApiRes = ({ traceId, traceResponse, serviceName = 'jaeger-all-in-one' }) => ({
url: `http://localhost:16686/api/traces/${traceId}`,
headers: { traceresponse: traceResponse || mockTraceResponse() },
json: JSON.parse(`{"data":[{"traceID":"${traceId}","spans":[{"traceID":"${traceId}","spanID":"${mockSpanId()}","operationName":"/api/services/{service}/operations","references":[],"startTime":1711683181193790,"duration":526,"tags":[{"key":"http.method","type":"string","value":"GET"},{"key":"http.scheme","type":"string","value":"http"},{"key":"net.host.name","type":"string","value":"localhost"},{"key":"net.host.port","type":"int64","value":16686},{"key":"net.sock.peer.addr","type":"string","value":"192.168.65.1"},{"key":"net.sock.peer.port","type":"int64","value":39977},{"key":"user_agent.original","type":"string","value":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"},{"key":"http.target","type":"string","value":"/api/services/tracing-demo/operations"},{"key":"net.protocol.version","type":"string","value":"1.1"},{"key":"http.route","type":"string","value":"/api/services/{service}/operations"},{"key":"http.wrote_bytes","type":"int64","value":652},{"key":"http.status_code","type":"int64","value":200},{"key":"span.kind","type":"string","value":"server"},{"key":"internal.span.format","type":"string","value":"otlp"}],"logs":[],"processID":"p1","warnings":null}],"processes":{"p1":{"serviceName":"${serviceName}","tags":[{"key":"host.name","type":"string","value":"a8446fbabf4b"},{"key":"os.type","type":"string","value":"linux"},{"key":"otel.library.name","type":"string","value":"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"},{"key":"otel.library.version","type":"string","value":"0.49.0"},{"key":"telemetry.sdk.language","type":"string","value":"go"},{"key":"telemetry.sdk.name","type":"string","value":"opentelemetry"},{"key":"telemetry.sdk.version","type":"string","value":"1.24.0"}]}},"warnings":null}],"total":0,"limit":0,"offset":0,"errors":null}`),
});

const mockSpanLog = (traceId, spanId) => `{"level":"debug","ts":1711677918.2096832,"caller":"app/span_processor.go:165","msg":"Span written to the storage by the collector","trace-id":"${traceId || mockTraceId()}","span-id":"${spanId || mockSpanId()}"}\n`;

const mockLogs = {
info: '{"level":"info","ts":1711677619.1002743,"caller":"[email protected]/clientconn.go:1223","msg":"[core][Channel #1 SubChannel #2] Subchannel Connectivity change to CONNECTING","system":"grpc","grpc_log":true}\n',
debug: mockSpanLog(),
warn: '{"level":"warn","ts":1711677618.112061,"caller":"[email protected]/warning.go:42","msg":"Using the 0.0.0.0 address exposes this server to every network interface, which may facilitate Denial of Service attacks. Enable the feature gate to change the default and remove this warning.","documentation":"https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/security-best-practices.md#safeguards-against-denial-of-service-attacks","feature gate ID":"component.UseLocalHostAsDefaultHost"}\n',
error: '{"level": "error","ts": 1680074638.9349482,"caller":"app/http_handler.go:495","msg":"HTTP handler, Internal Server Error","error":"grpc stream error: rpc error: code = ResourceExhausted desc = grpc: received message larger than max (7833328 vs. 4194304)","stacktrace":"mock stacktrace"}\n',
fatal: '{"level":"fatal","ts":1711678733.242641,"caller":"all-in-one/main.go:114","msg":"Failed to init storage factory","error":"failed to create primary Elasticsearch client: health check timeout: Head \\"http://elasticsearch:9200\\": dial tcp: lookup elasticsearch on 127.0.0.11:53: no such host: no Elasticsearch node available","stacktrace":"mock stacktrace"}\n',
};

module.exports = {
mockLogs,
mockJaegerApiRes,
mockSpanLog,
mockTraceId,
mockSpanId,
mockTraceResponse,
};
36 changes: 36 additions & 0 deletions packages/one-app-runner/__fixtures__/logStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed 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.
*/

const { Writable } = require('node:stream');

class MockLogStream extends Writable {
constructor() {
super({ objectMode: true });
this.logs = [];
}

// eslint-disable-next-line no-underscore-dangle -- this is the Writable stream API
_destroy(error, callback) {
this.logs = [];
callback(error);
}

// eslint-disable-next-line no-underscore-dangle -- this is the Writable stream API
_write(chunk, encoding, callback) {
this.logs.push(chunk.toString());
callback();
}
}

module.exports = MockLogStream;
19 changes: 19 additions & 0 deletions packages/one-app-runner/__mocks__/colorette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed 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.
*/

const colorette = jest.requireActual('colorette');

module.exports = {
createColors: colorette.createColors.bind(colorette, { useColor: false }),
};
49 changes: 49 additions & 0 deletions packages/one-app-runner/__mocks__/node-fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed 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.
*/

const { Headers } = jest.requireActual('node-fetch');

const promises = [];
const responses = new Map();

const fetchMock = jest.fn((url) => {
const response = responses.get(url) || {};
const fetchPromise = Promise.resolve({
ok: response.ok ?? true,
status: response.status ?? 200,
headers: new Headers(response.headers),
json: () => {
const jsonPromise = Promise.resolve(response.json ?? {});
promises.push(jsonPromise);
return jsonPromise;
},
});
promises.push(fetchPromise);
return fetchPromise;
});

fetchMock.mockResponse = ({ url, ...res }) => {
responses.set(url, res);
};

fetchMock.drain = async () => {
await Promise.all(promises);
promises.length = 0;
};

fetchMock.clearResponses = () => {
responses.clear();
};

module.exports = fetchMock;
34 changes: 34 additions & 0 deletions packages/one-app-runner/__mocks__/node:child_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed 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.
*/

const makeMockSpawn = require('mock-spawn');

let spawn;

function printCall(i) {
return `${spawn.calls[i].command} ${spawn.calls[i].args.join(' ')}`;
}

const mockChildProcess = {
get spawn() { return spawn; },
resetSpawn() {
spawn = makeMockSpawn();
spawn.setSignals({ SIGINT: true, SIGTERM: true });
spawn.printCall = printCall;
},
};

mockChildProcess.resetSpawn();

module.exports = mockChildProcess;
8 changes: 0 additions & 8 deletions packages/one-app-runner/__tests__/.eslintrc.json

This file was deleted.

Loading

0 comments on commit bb5a6be

Please sign in to comment.