Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(observability): fix bugs found from product review + negative cases #2158

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions observability-test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

class FakeSession {
calledWith_: IArguments;
formattedName_: any;

Check warning on line 93 in observability-test/database.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
constructor() {
this.calledWith_ = arguments;
}
Expand Down Expand Up @@ -504,7 +504,7 @@

let beginSnapshotStub: sinon.SinonStub;
let getSessionStub: sinon.SinonStub;
let snapshotStub: sinon.SinonStub;

Check warning on line 507 in observability-test/database.ts

View workflow job for this annotation

GitHub Actions / lint

'snapshotStub' is assigned a value but never used

beforeEach(() => {
fakePool = database.pool_;
Expand Down Expand Up @@ -605,7 +605,7 @@
// pool, so that the pool can remove it from its inventory.
const releaseStub = sandbox.stub(fakePool, 'release');

database.getSnapshot((err, snapshot) => {
database.getSnapshot(async (err, snapshot) => {
assert.ifError(err);
assert.strictEqual(snapshot, fakeSnapshot2);
// The first session that error should already have been released back
Expand All @@ -616,8 +616,9 @@
snapshot.emit('end');
assert.strictEqual(releaseStub.callCount, 2);

await provider.forceFlush();
await traceExporter.forceFlush();
const spans = traceExporter.getFinishedSpans();
assert.strictEqual(spans.length, 2, 'Exactly 2 spans expected');
withAllSpansHaveDBName(spans);

const actualSpanNames: string[] = [];
Expand All @@ -640,7 +641,7 @@
);

// Ensure that the first span actually produced an error that was recorded.
const parentSpan = spans[1];
const parentSpan = spans[0];
assert.strictEqual(
SpanStatusCode.ERROR,
parentSpan.status.code,
Expand All @@ -653,7 +654,7 @@
);

// Ensure that the second span is a child of the first span.
const secondRetrySpan = spans[0];
const secondRetrySpan = spans[1];
assert.ok(
parentSpan.spanContext().traceId,
'Expected that the initial parent span has a defined traceId'
Expand Down Expand Up @@ -774,6 +775,7 @@
callback(null, RESPONSE);
},
once() {},
end() {},
};

database.batchTransaction = (identifier, options) => {
Expand All @@ -782,10 +784,14 @@
return fakeTransaction;
};

database.createBatchTransaction(opts, (err, transaction, resp) => {
database.createBatchTransaction(opts, async (err, transaction, resp) => {
assert.strictEqual(err, null);
assert.strictEqual(transaction, fakeTransaction);
assert.strictEqual(resp, RESPONSE);
transaction!.end();

await provider.forceFlush();
traceExporter.forceFlush();
const spans = traceExporter.getFinishedSpans();
assert.strictEqual(spans.length, 1, 'Exactly 1 span expected');
withAllSpansHaveDBName(spans);
Expand Down Expand Up @@ -839,8 +845,8 @@
begin(callback) {
callback(error, RESPONSE);
},

once() {},
end() {},
};

database.batchTransaction = () => {
Expand Down Expand Up @@ -926,9 +932,11 @@

getSessionStub.callsFake(callback => callback(fakeError));

database.getTransaction(err => {
database.getTransaction(async err => {
assert.strictEqual(err, fakeError);

await provider.forceFlush();
traceExporter.forceFlush();
const spans = traceExporter.getFinishedSpans();
assert.strictEqual(spans.length, 1, 'Exactly 1 span expected');
withAllSpansHaveDBName(spans);
Expand Down Expand Up @@ -978,6 +986,7 @@
database.getTransaction((err, transaction) => {
assert.ifError(err);
assert.strictEqual(transaction, fakeTransaction);
transaction!.end();

const spans = traceExporter.getFinishedSpans();
withAllSpansHaveDBName(spans);
Expand Down Expand Up @@ -1163,7 +1172,7 @@

it('with error on null mutation should catch thrown error', done => {
try {
database.writeAtLeastOnce(null, (err, res) => {});

Check warning on line 1175 in observability-test/database.ts

View workflow job for this annotation

GitHub Actions / lint

'err' is defined but never used
} catch (err) {
// Performing a substring search on the error because
// depending on the version of Node.js, the error might be either of:
Expand Down Expand Up @@ -1869,11 +1878,14 @@
.on('error', err => {
assert.fail(err);
})
.on('end', () => {
.on('end', async () => {
assert.strictEqual(endStub.callCount, 1);
assert.strictEqual(endStub2.callCount, 1);
assert.strictEqual(rows, 1);

await provider.forceFlush();
await traceExporter.forceFlush();

const spans = traceExporter.getFinishedSpans();
assert.strictEqual(spans.length, 2, 'Exactly 1 span expected');
withAllSpansHaveDBName(spans);
Expand All @@ -1898,35 +1910,35 @@
);

// Ensure that the span actually produced an error that was recorded.
const secondSpan = spans[1];
assert.strictEqual(
const lastSpan = spans[0];
assert.deepStrictEqual(
SpanStatusCode.ERROR,
secondSpan.status.code,
lastSpan.status.code,
'Expected an ERROR span status'
);
assert.strictEqual(
assert.deepStrictEqual(
'Session not found',
secondSpan.status.message,
lastSpan.status.message,
'Mismatched span status message'
);

// Ensure that the final span that got retries did not error.
const firstSpan = spans[0];
assert.strictEqual(
const firstSpan = spans[1];
assert.deepStrictEqual(
SpanStatusCode.UNSET,
firstSpan.status.code,
'Unexpected an span status code'
'Unexpected span status code'
);
assert.strictEqual(
assert.deepStrictEqual(
undefined,
firstSpan.status.message,
'Unexpected span status message'
);

const expectedEventNames = [
'Using Session',
'Using Session',
'No session available',
'Using Session',
];
assert.deepStrictEqual(
actualEventNames,
Expand Down
Loading
Loading