Skip to content

fix various issue in admin and monitorService #2424

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

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fix various issue in monitor service, file naming issue and export admin service from node-core

## [10.4.0] - 2024-06-05
### Added
- Add monitor service to record block indexing actions in order to improve POI accuracy, and provide debug info for Admin api
Expand Down
1 change: 1 addition & 0 deletions packages/node-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './utils';
export * from './indexer';
export * from './subcommands';
export * from './yargs';
export * from './admin';
19 changes: 18 additions & 1 deletion packages/node-core/src/indexer/monitor.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import fs from 'fs';
import path from 'path';
import {makeTempDir} from '@subql/common';
import {NodeConfig} from '../configure';
import {MonitorService} from './monitor.service';
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('Monitor service', () => {
let nodeConfig: NodeConfig;
beforeEach(async () => {
monitorDir = await makeTempDir();
nodeConfig = {monitorOutDir: monitorDir, monitorFileSize: 1024} as NodeConfig;
nodeConfig = {monitorOutDir: monitorDir, monitorFileSize: 1024, dbSchema: 'test-db'} as NodeConfig;
monitorService1 = new testMonitorService(nodeConfig);
monitorService1.resetAll();
});
Expand Down Expand Up @@ -208,4 +209,20 @@ describe('Monitor service', () => {
monitorService2.testInit();
expect(spyResetAll).toHaveBeenCalledTimes(1);
});

it('should generate correct file path with sanitized dbSchema', () => {
const expectedPath1 = path.join(monitorDir, 'test-db-fileA.txt');
expect((monitorService1 as any).getFilePath('A')).toBe(expectedPath1);

const nodeConfig2 = {
monitorOutDir: monitorDir,
monitorFileSize: 1024,
dbSchema: 'd-1234/subquery/subquery-mainnet',
} as NodeConfig;
const monitorService2 = new testMonitorService(nodeConfig2);
const expectedPath2 = path.join(monitorDir, 'd-1234-subquery-subquery-mainnet-fileA.txt');
const indexPath = path.join(monitorDir, 'd-1234-subquery-subquery-mainnet-index.csv');
expect((monitorService2 as any).getFilePath('A')).toBe(expectedPath2);
expect((monitorService2 as any).indexPath).toBe(indexPath);
});
});
8 changes: 6 additions & 2 deletions packages/node-core/src/indexer/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface MonitorServiceInterface {
createBlockStart(blockHeight: number): void;
}

function sanitizeDbName(dbName: string): string {
return dbName.replace(/[\\/]/g, '-');
}

@Injectable()
export class MonitorService implements MonitorServiceInterface {
private readonly outputPath: string;
Expand All @@ -52,7 +56,7 @@ export class MonitorService implements MonitorServiceInterface {
constructor(protected config: NodeConfig) {
this.outputPath = config.monitorOutDir;
this.monitorFileSize = config.monitorFileSize * UNIT_MB;
this.indexPath = path.join(this.outputPath, `${this.config.dbSchema}-index.csv`);
this.indexPath = path.join(this.outputPath, `${sanitizeDbName(this.config.dbSchema)}-index.csv`);
this.init();
setMonitorService(this);
}
Expand Down Expand Up @@ -383,7 +387,7 @@ export class MonitorService implements MonitorServiceInterface {
}

private getFilePath(file: keyof typeof FileLocation): string {
return path.join(this.outputPath, `${this.config.dbSchema}-${FileLocation[file]}`);
return path.join(this.outputPath, `${sanitizeDbName(this.config.dbSchema)}-${FileLocation[file]}`);
}

private updateIndex(indexEntry: IndexEntry): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fix import admin from node-core, update dockerfile to fix monitor default directory permission issue

## [4.6.0] - 2024-06-05
### Added
- Add monitor service to record block indexing actions in order to improve POI accuracy, and provide debug info for Admin api
Expand Down
4 changes: 4 additions & 0 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ RUN apk add --no-cache tini curl git && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache

# Create ./.monitor directory and set permissions
RUN mkdir -p .monitor && \
chown 1000:1000 .monitor

# Make the user not ROOT
USER 1000

Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
import { adminControllers, adminServices } from '@subql/node-core/admin';
import { adminControllers, adminServices } from '@subql/node-core';
import { FetchModule } from '../indexer/fetch.module';

@Module({
Expand Down
Loading