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: Enable Logging functionality to both new and old Log Tables #657

Merged
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4ada070
fix: relocated runLogsSql into setupPartitionLogsTable
Kevin101Zhang Apr 4, 2024
8b57a79
chore: add prefix for INDEXs in schema
Kevin101Zhang Apr 4, 2024
a709dae
feat: added log-entry class and test
Kevin101Zhang Apr 5, 2024
f4c7ccb
Update log-entry.test.ts
Kevin101Zhang Apr 5, 2024
9de783f
Update log-entry.test.ts
Kevin101Zhang Apr 5, 2024
89fa865
uncommented out provisioning
Kevin101Zhang Apr 8, 2024
8d0da62
feat: added additional static classes in LogEntry
Kevin101Zhang Apr 8, 2024
91a3d1b
fix: modified indexer-logger and test to use logEntry
Kevin101Zhang Apr 8, 2024
0be44dd
fix: typo
Kevin101Zhang Apr 8, 2024
8a331b2
Update log-entry.test.ts
Kevin101Zhang Apr 8, 2024
1809f7a
chore: removed console.log
Kevin101Zhang Apr 8, 2024
7254a50
fix: LogLevel and LogType are defined in log-entry
Kevin101Zhang Apr 8, 2024
749e9f2
fix: indexer-logger now matches exact query
Kevin101Zhang Apr 8, 2024
00a6e61
Merge branch '639-fix-unresolved-comments-in-original-pr-httpsgithubc…
Kevin101Zhang Apr 8, 2024
a582921
fix: added test without bh
Kevin101Zhang Apr 8, 2024
8459863
Merge branch '639-fix-unresolved-comments-in-original-pr-httpsgithubc…
Kevin101Zhang Apr 8, 2024
0301061
merge scripts
Kevin101Zhang Apr 8, 2024
97e6ebc
fix: used fake timers on indexer-logger test
Kevin101Zhang Apr 9, 2024
4e431e9
fix: writeLog exclusively accepts an array of LogEntry
Kevin101Zhang Apr 9, 2024
6193ade
Merge branch '639-fix-unresolved-comments-in-original-pr-httpsgithubc…
Kevin101Zhang Apr 9, 2024
954528e
chore: moved log-entry files to indexer-logger
Kevin101Zhang Apr 9, 2024
70c9153
rebase
Kevin101Zhang Apr 9, 2024
16e9b69
rebase
Kevin101Zhang Apr 9, 2024
030fa4c
feat: provisioning of new users
Kevin101Zhang Apr 10, 2024
f7de470
merge with main includes - feat: Provision logs for existing users
Kevin101Zhang Apr 10, 2024
03ded3f
chore: remove console.log
Kevin101Zhang Apr 10, 2024
8d48fc5
added back commented out test for metaDataTableDDL
Kevin101Zhang Apr 10, 2024
80eb9f1
uncommented skip
Kevin101Zhang Apr 10, 2024
451b5bc
Merge branch '641-introduce-provisioning-of-logs' of https://github.c…
Kevin101Zhang Apr 10, 2024
e097cbc
uncommented skip, removed redundant test cases
Kevin101Zhang Apr 10, 2024
c9fc515
chore: removed comment
Kevin101Zhang Apr 10, 2024
c862042
chore: removed comment
Kevin101Zhang Apr 10, 2024
ef4d29c
mocked provisionLogsIfNeeded for test
Kevin101Zhang Apr 10, 2024
d75bc77
feat: uncommented out logging to new log table
Kevin101Zhang Apr 10, 2024
e8de5b8
chore: commented out unused code
Kevin101Zhang Apr 10, 2024
3ee3c9a
rebase
Kevin101Zhang Apr 10, 2024
39e4078
rebase from main
Kevin101Zhang Apr 10, 2024
5efbc81
add nullish coalescing to getDatabaseConnectionParameters
Kevin101Zhang Apr 10, 2024
d68a242
feat: added unit test to check logs, removed unused line
Kevin101Zhang Apr 14, 2024
d6285fe
feat: added integration test for logs asserting log_entries are equal…
Kevin101Zhang Apr 14, 2024
2ba9ffd
rebase
Kevin101Zhang Apr 15, 2024
d5f87de
fix: corrected param for indexerMeta instantiation
Kevin101Zhang Apr 15, 2024
6ed96aa
fix: use IndexerConfig for indexerMeta
Kevin101Zhang Apr 15, 2024
11dfe35
searching for provisioning endpoints
Kevin101Zhang Apr 15, 2024
b960b2c
fix: check run functions
Kevin101Zhang Apr 15, 2024
a3a040e
chore: renamed log table
Kevin101Zhang Apr 16, 2024
845cfac
chore: spacing
Kevin101Zhang Apr 16, 2024
1ead54b
set systemLogs in buildDB context to user
Kevin101Zhang Apr 16, 2024
4e718d6
fix: use of IndexerConfig in indexerMeta
Kevin101Zhang Apr 16, 2024
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
111 changes: 80 additions & 31 deletions runner/src/indexer/indexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type fetch from 'node-fetch';
import Indexer from './indexer';
import { VM } from 'vm2';
import DmlHandler from '../dml-handler/dml-handler';
// import IndexerMeta from '../indexer-meta/indexer-meta';
import type IndexerMeta from '../indexer-meta/indexer-meta';
import type PgClient from '../pg-client';
import { type IndexerBehavior } from '../stream-handler/stream-handler';
import { LogLevel } from '../indexer-meta/log-entry';
Expand Down Expand Up @@ -197,11 +197,11 @@ CREATE TABLE
delete: jest.fn().mockReturnValue([]),
} as unknown as DmlHandler;

// const genericMockIndexerMeta : any = {
// writeLogs: jest.fn(),
// setStatus: jest.fn(),
// updateBlockheight: jest.fn()
// } as unknown as IndexerMeta;
const genericMockIndexerMeta: any = {
writeLogs: jest.fn(),
setStatus: jest.fn(),
updateBlockheight: jest.fn()
} as unknown as IndexerMeta;

const genericDbCredentials: any = {
database: 'test_near',
Expand Down Expand Up @@ -242,7 +242,7 @@ CREATE TABLE
fetch: mockFetch as unknown as typeof fetch,
provisioner: genericProvisioner,
dmlHandler: genericMockDmlHandler,
// indexerMeta: genericMockIndexerMeta ,
indexerMeta: genericMockIndexerMeta,
}, undefined, config);

const functions: Record<string, any> = {};
Expand Down Expand Up @@ -296,7 +296,7 @@ CREATE TABLE
dmlHandler: genericMockDmlHandler
}, undefined, config);

const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE /** [] */);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE, []);

const query = `
query {
Expand Down Expand Up @@ -351,7 +351,7 @@ CREATE TABLE
dmlHandler: genericMockDmlHandler
}, undefined, config);

const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE /** [] */);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE, []);

await context.fetchFromSocialApi('/index', {
method: 'POST',
Expand Down Expand Up @@ -380,7 +380,7 @@ CREATE TABLE
});
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, dmlHandler: genericMockDmlHandler }, undefined, config);

const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, INVALID_HASURA_ROLE /** [] */);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, INVALID_HASURA_ROLE, []);

await expect(async () => await context.graphql('query { hello }')).rejects.toThrow('boom');
});
Expand All @@ -395,7 +395,7 @@ CREATE TABLE
});
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, dmlHandler: genericMockDmlHandler }, undefined, config);

const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE /** [] */);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE, []);

const query = 'query($name: String) { hello(name: $name) }';
const variables = { name: 'morgan' };
Expand Down Expand Up @@ -516,7 +516,7 @@ CREATE TABLE
);`;

// Does not outright throw an error but instead returns an empty object
expect(indexer.buildDatabaseContext('test_account', 'test_schema_name', schemaWithDuplicateSanitizedTableNames, 1 /** [] */))
expect(indexer.buildDatabaseContext('test_account', 'test_schema_name', schemaWithDuplicateSanitizedTableNames, 1, []))
.toStrictEqual({});
});

Expand All @@ -528,7 +528,7 @@ CREATE TABLE
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);

const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres' /** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

const objToInsert = [{
account_id: 'morgs_near',
Expand Down Expand Up @@ -562,7 +562,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres' /** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);
const promises = [];

for (let i = 1; i <= 100; i++) {
Expand Down Expand Up @@ -597,7 +597,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres' /** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

const objToSelect = {
account_id: 'morgs_near',
Expand All @@ -623,7 +623,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres' /** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

const whereObj = {
account_id: 'morgs_near',
Expand Down Expand Up @@ -653,7 +653,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres' /** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

const objToInsert = [{
account_id: 'morgs_near',
Expand Down Expand Up @@ -685,7 +685,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: mockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres'/** [] */);
const context = indexer.buildContext(SOCIAL_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

const deleteFilter = {
account_id: 'morgs_near',
Expand All @@ -700,7 +700,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: genericMockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext(STRESS_TEST_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres'/** [] */);
const context = indexer.buildContext(STRESS_TEST_SCHEMA, 'morgs.near/social_feed1', 1, 'postgres', []);

expect(Object.keys(context.db)).toStrictEqual([
'CreatorQuest',
Expand Down Expand Up @@ -738,7 +738,7 @@ CREATE TABLE
fetch: genericMockFetch as unknown as typeof fetch,
dmlHandler: genericMockDmlHandler
}, genericDbCredentials, config);
const context = indexer.buildContext('', 'morgs.near/social_feed1', 1, 'postgres'/** [] */);
const context = indexer.buildContext('', 'morgs.near/social_feed1', 1, 'postgres', []);

expect(Object.keys(context.db)).toStrictEqual([]);
});
Expand Down Expand Up @@ -806,7 +806,7 @@ CREATE TABLE
},
shards: {}
} as unknown as StreamerMessage) as unknown as Block;
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: genericMockDmlHandler/** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {};
functions['buildnear.testnet/test'] = {
Expand Down Expand Up @@ -885,7 +885,7 @@ CREATE TABLE
},
shards: {}
} as unknown as StreamerMessage) as unknown as Block;
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: genericMockDmlHandler/** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {};
functions['buildnear.testnet/test'] = {
Expand Down Expand Up @@ -922,7 +922,7 @@ CREATE TABLE
provisionUserApi: jest.fn(),
provisionLogsIfNeeded: jest.fn(),
};
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions = {
'morgs.near/test': {
Expand Down Expand Up @@ -967,7 +967,7 @@ CREATE TABLE
provisionUserApi: jest.fn(),
provisionLogsIfNeeded: jest.fn(),
};
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {
'morgs.near/test': {
Expand Down Expand Up @@ -1004,7 +1004,7 @@ CREATE TABLE
provisionUserApi: jest.fn(),
provisionLogsIfNeeded: jest.fn(),
};
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {
'morgs.near/test': {
Expand Down Expand Up @@ -1043,7 +1043,7 @@ CREATE TABLE
provisionUserApi: jest.fn(),
provisionLogsIfNeeded: jest.fn(),
};
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {
'morgs.near/test': {
Expand Down Expand Up @@ -1083,7 +1083,7 @@ CREATE TABLE
fetchUserApiProvisioningStatus: jest.fn().mockReturnValue(false),
provisionUserApi: jest.fn().mockRejectedValue(error),
};
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ }, undefined, config);
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch, provisioner, dmlHandler: genericMockDmlHandler, indexerMeta: genericMockIndexerMeta }, undefined, config);

const functions: Record<string, any> = {
'morgs.near/test': {
Expand Down Expand Up @@ -1145,19 +1145,19 @@ CREATE TABLE

const indexerDebug = new Indexer(
{ log_level: LogLevel.DEBUG },
{ fetch: mockFetchDebug as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ },
{ fetch: mockFetchDebug as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler, indexerMeta: genericMockIndexerMeta },
undefined,
config
);
const indexerInfo = new Indexer(
{ log_level: LogLevel.INFO },
{ fetch: mockFetchInfo as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ },
{ fetch: mockFetchInfo as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler, indexerMeta: genericMockIndexerMeta },
undefined,
config
);
const indexerError = new Indexer(
{ log_level: LogLevel.ERROR },
{ fetch: mockFetchError as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler /** , indexerMeta: genericMockIndexerMeta */ },
{ fetch: mockFetchError as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: mockDmlHandler, indexerMeta: genericMockIndexerMeta },
undefined,
config
);
Expand Down Expand Up @@ -1222,7 +1222,7 @@ CREATE TABLE
});
const role = 'morgs_near';
const indexer = new Indexer(defaultIndexerBehavior, { fetch: mockFetch as unknown as typeof fetch }, undefined, config);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE/** [] */);
const context = indexer.buildContext(SIMPLE_SCHEMA, INDEXER_NAME, 1, HASURA_ROLE, []);

const mutation = `
mutation {
Kevin101Zhang marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1248,4 +1248,53 @@ CREATE TABLE
}
]);
});

it('call writeLogs method at the end of execution with correct and all logs are present', async () => {
const mockFetchDebug = jest.fn(() => ({
status: 200,
json: async () => ({
errors: null,
}),
}));

const blockHeight = 456;
const mockBlock = Block.fromStreamerMessage({
block: {
chunks: [],
header: {
height: blockHeight
}
},
shards: {}
} as unknown as StreamerMessage) as unknown as Block;

const indexerMeta: any = {
writeLogs: jest.fn(),
};

const functions: Record<string, any> = {};
functions['buildnear.testnet/test'] = {
code: `
console.debug('debug log');
console.log('info log');
console.error('error log');
await context.db.Posts.select({
account_id: 'morgs_near',
receipt_id: 'abc',
});
`,
schema: SIMPLE_SCHEMA
};

const indexerDebug = new Indexer(
{ log_level: LogLevel.DEBUG },
{ fetch: mockFetchDebug as unknown as typeof fetch, provisioner: genericProvisioner, dmlHandler: genericMockDmlHandler, indexerMeta },
undefined,
config
);

await indexerDebug.runFunctions(mockBlock, functions, false);
expect(indexerMeta.writeLogs).toHaveBeenCalledTimes(1);
expect(indexerMeta.writeLogs.mock.calls[0][0]).toHaveLength(5);
Kevin101Zhang marked this conversation as resolved.
Show resolved Hide resolved
});
});
Loading