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:elk logging (DO NOT MERGE) #1061

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,15 @@ SCHEMA_FILE_SERVER_TOKEN=xxxxxxxx // Please provide schema file server token for

FILEUPLOAD_CACHE_TTL= //Provide file upload cache ttl

FIELD_UPLOAD_SIZE= //Provide field upload size
FIELD_UPLOAD_SIZE= //Provide field upload size

ORGANIZATION=credebl
CONTEXT=platform
APP=api

CONSOLE_LOG=true
ELK_LOG=true
LOG_LEVEL=debug
ELK_LOG_PATH = "http://localhost:9200/"
ELK_USERNAME=elastic
ELK_PASSWORD=xxxxxx
16 changes: 14 additions & 2 deletions apps/agent-provisioning/src/agent-provisioning.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { AgentProvisioningService } from './agent-provisioning.service';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule } from '@nestjs/config';
import { getNatsOptions } from '@credebl/common/nats.config';
import { CommonConstants } from '@credebl/common/common.constant';
import { CommonConstants, MICRO_SERVICE_NAME } from '@credebl/common/common.constant';
import { GlobalConfigModule } from '@credebl/config/global-config.module';
import { LoggerModule } from '@credebl/logger/logger.module';
import { ContextInterceptorModule } from '@credebl/context/contextInterceptorModule';
import { ConfigModule as PlatformConfig } from '@credebl/config/config.module';
@Module({
imports: [
ConfigModule.forRoot(),
GlobalConfigModule,
LoggerModule, PlatformConfig, ContextInterceptorModule,
ClientsModule.register([
{
name: 'NATS_CLIENT',
Expand All @@ -18,6 +24,12 @@ import { CommonConstants } from '@credebl/common/common.constant';
])
],
controllers: [AgentProvisioningController],
providers: [AgentProvisioningService, Logger]
providers: [
AgentProvisioningService, Logger,
{
provide: MICRO_SERVICE_NAME,
useValue: 'Agent-provisioning' // Provide the name directly
}
]
})
export class AgentProvisioningModule { }
2 changes: 2 additions & 0 deletions apps/agent-provisioning/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AgentProvisioningModule } from './agent-provisioning.module';
import { getNatsOptions } from '@credebl/common/nats.config';
import { CommonConstants } from '@credebl/common/common.constant';
import NestjsLoggerServiceAdapter from '@credebl/logger/nestjsLoggerServiceAdapter';
const logger = new Logger();

async function bootstrap(): Promise<void> {
Expand All @@ -13,6 +14,7 @@ async function bootstrap(): Promise<void> {
transport: Transport.NATS,
options: getNatsOptions(CommonConstants.AGENT_PROVISIONING, process.env.AGENT_PROVISIONING_NKEY_SEED)
});
app.useLogger(app.get(NestjsLoggerServiceAdapter));
app.useGlobalFilters(new HttpExceptionFilter());

await app.listen();
Expand Down
16 changes: 14 additions & 2 deletions apps/agent-service/src/agent-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import { ConnectionRepository } from 'apps/connection/src/connection.repository'
import { CacheModule } from '@nestjs/cache-manager';
import { getNatsOptions } from '@credebl/common/nats.config';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { CommonConstants } from '@credebl/common/common.constant';
import { CommonConstants, MICRO_SERVICE_NAME } from '@credebl/common/common.constant';
import { LoggerModule } from '@credebl/logger/logger.module';
import { ConfigModule as PlatformConfig } from '@credebl/config/config.module';
import { GlobalConfigModule } from '@credebl/config/global-config.module';
import { ContextInterceptorModule } from '@credebl/context/contextInterceptorModule';
import { NATSClient } from 'libs/common/NATSClient';

@Module({
imports: [
ConfigModule.forRoot(),
GlobalConfigModule,
LoggerModule, PlatformConfig, ContextInterceptorModule,
ClientsModule.register([
{
name: 'NATS_CLIENT',
Expand All @@ -34,7 +41,12 @@ import { CommonConstants } from '@credebl/common/common.constant';
Logger,
ConnectionService,
ConnectionRepository,
UserActivityRepository
UserActivityRepository,
{
provide: MICRO_SERVICE_NAME,
useValue: 'Agent-service' // Provide the name directly
},
NATSClient
],
exports: [AgentServiceService, AgentServiceRepository, AgentServiceModule]
})
Expand Down
9 changes: 6 additions & 3 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ import { InvitationMessage } from '@credebl/common/interfaces/agent-service.inte
import * as CryptoJS from 'crypto-js';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { PrismaService } from '@credebl/prisma-service';
import { NATSClient } from 'libs/common/NATSClient';
import { from } from 'rxjs';

@Injectable()
@WebSocketGateway()
Expand All @@ -89,7 +91,8 @@ export class AgentServiceService {
private readonly connectionService: ConnectionService,
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy,
@Inject(CACHE_MANAGER) private cacheService: Cache,
private readonly userActivityRepository: UserActivityRepository
private readonly userActivityRepository: UserActivityRepository,
private natsClient : NATSClient
) {}

async ReplaceAt(input, search, replace, start, end): Promise<string> {
Expand Down Expand Up @@ -1896,8 +1899,8 @@ export class AgentServiceService {
response: string;
}> {
try {
return this.agentServiceProxy
.send<string>(pattern, payload)
return from(this.natsClient
.send<string>(this.agentServiceProxy, pattern, payload))
.pipe(map((response) => ({ response })))
.toPromise()
.catch((error) => {
Expand Down
2 changes: 2 additions & 0 deletions apps/agent-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { getNatsOptions } from '@credebl/common/nats.config';
import { CommonConstants } from '@credebl/common/common.constant';
import { Ledgers } from '@credebl/enum/enum';
import NestjsLoggerServiceAdapter from '@credebl/logger/nestjsLoggerServiceAdapter';

const logger = new Logger();

Expand All @@ -18,6 +19,7 @@ async function bootstrap(): Promise<void> {
options: getNatsOptions(CommonConstants.AGENT_SERVICE, process.env.AGENT_SERVICE_NKEY_SEED)

});
app.useLogger(app.get(NestjsLoggerServiceAdapter));
app.useGlobalFilters(new HttpExceptionFilter());

await app.listen();
Expand Down
3 changes: 2 additions & 1 deletion apps/api-gateway/src/agent-service/agent-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AgentController } from './agent-service.controller';
import { AgentService } from './agent-service.service';
import { getNatsOptions } from '@credebl/common/nats.config';
import { CommonConstants } from '@credebl/common/common.constant';
import { NATSClient } from 'libs/common/NATSClient';

@Module({
imports: [
Expand All @@ -24,6 +25,6 @@ import { CommonConstants } from '@credebl/common/common.constant';
])
],
controllers: [AgentController],
providers: [AgentService, CommonService]
providers: [AgentService, CommonService, NATSClient]
})
export class AgentModule { }
22 changes: 12 additions & 10 deletions apps/api-gateway/src/agent-service/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { AgentStatus } from './interface/agent-service.interface';
import { CreateDidDto } from './dto/create-did.dto';
import { CreateWalletDto } from './dto/create-wallet.dto';
import { AgentConfigureDto } from './dto/agent-configure.dto';
import { NATSClient } from 'libs/common/NATSClient';

@Injectable()
export class AgentService extends BaseService {
constructor(
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy,
private natsClient : NATSClient
) {
super('AgentService');
}
Expand All @@ -28,63 +30,63 @@ export class AgentService extends BaseService {
const payload = { agentSpinupDto, user };

// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'agent-spinup', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'agent-spinup', payload);
}

async createTenant(createTenantDto: CreateTenantDto, user: user): Promise<AgentSpinUpSatus> {
const payload = { createTenantDto, user };

// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'create-tenant', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'create-tenant', payload);
}

async createDid(createDidDto: CreateDidDto, orgId:string, user: user): Promise<object> {
const payload = { createDidDto, orgId, user };

// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'create-did', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'create-did', payload);
}

async createWallet(createWalletDto: CreateWalletDto, user: user): Promise<IWalletRecord> {
const payload = { createWalletDto, user };
// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'create-wallet', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'create-wallet', payload);
}

async getAgentHealth(user: user, orgId:string): Promise<AgentStatus> {
const payload = { user, orgId };

// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'agent-health', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'agent-health', payload);

}

async getLedgerConfig(user: user): Promise<object> {
const payload = { user };

// NATS call
return this.sendNatsMessage(this.agentServiceProxy, 'get-ledger-config', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'get-ledger-config', payload);
}

async createSecp256k1KeyPair(orgId:string): Promise<object> {
const payload = {orgId};
// NATS call

return this.sendNatsMessage(this.agentServiceProxy, 'polygon-create-keys', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'polygon-create-keys', payload);
}

async agentConfigure(agentConfigureDto: AgentConfigureDto, user: user): Promise<object> {
const payload = { agentConfigureDto, user };
// NATS call

return this.sendNatsMessage(this.agentServiceProxy, 'agent-configure', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'agent-configure', payload);
}

async deleteWallet(orgId: string, user: user): Promise<object> {
const payload = { orgId, user };
// NATS call

return this.sendNatsMessage(this.agentServiceProxy, 'delete-wallet', payload);
return this.natsClient.sendNatsMessage(this.agentServiceProxy, 'delete-wallet', payload);
}

}
3 changes: 2 additions & 1 deletion apps/api-gateway/src/agent/agent.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CommonModule } from '../../../../libs/common/src/common.module';
import { CommonService } from '../../../../libs/common/src/common.service';
import { ConfigModule } from '@nestjs/config';
import { commonNatsOptions } from 'libs/service/nats.options';
import { NATSClient } from 'libs/common/NATSClient';

@Module({
imports: [
Expand All @@ -21,6 +22,6 @@ import { commonNatsOptions } from 'libs/service/nats.options';
])
],
controllers: [AgentController],
providers: [AgentService, CommonService]
providers: [AgentService, CommonService, NATSClient]
})
export class AgentModule { }
24 changes: 13 additions & 11 deletions apps/api-gateway/src/agent/agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';

import { WalletDetailsDto } from '../dtos/wallet-details.dto';
import { NATSClient } from 'libs/common/NATSClient';

@Injectable()
export class AgentService extends BaseService {
constructor(
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy,
private natsClient : NATSClient
) {
super('AgentService');
}
Expand All @@ -27,29 +29,29 @@ export class AgentService extends BaseService {
getAllDid(_public: boolean, verkey: string, did: string, user: any) {
this.logger.log('**** getAllDid called...');
const payload = { _public, verkey, did, user };
return this.sendNats(this.agentServiceProxy, 'get-all-did', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'get-all-did', payload);
}

/**
* Description: Calling agent service for create-local-did
*/
createLocalDid(user: any) {
this.logger.log('**** createLocalDid called...');
return this.sendNats(this.agentServiceProxy, 'create-local-did', user);
return this.natsClient.sendNats(this.agentServiceProxy, 'create-local-did', user);
}

async walletProvision(walletUserDetails: WalletDetailsDto, user: any) {
this.logger.log(`**** walletProvision called...${JSON.stringify(walletUserDetails)}`);
const payload = { walletUserDetails, user };
return await this.sendNats(this.agentServiceProxy, 'wallet-provision', payload);
return await this.natsClient.sendNats(this.agentServiceProxy, 'wallet-provision', payload);
}

/**
* Description: Calling agent service for get-public-did
*/
getPublicDid(user: any) {
this.logger.log('**** getPublicDid called...');
return this.sendNats(this.agentServiceProxy, 'get-public-did', user);
return this.natsClient.sendNats(this.agentServiceProxy, 'get-public-did', user);
}

/**
Expand All @@ -59,7 +61,7 @@ export class AgentService extends BaseService {
assignPublicDid(id: number, user: any) {
this.logger.log('**** assignPublicDid called...');
const payload = { id, user };
return this.sendNats(this.agentServiceProxy, 'assign-public-did-org', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'assign-public-did-org', payload);
}


Expand All @@ -73,28 +75,28 @@ export class AgentService extends BaseService {
registerNym(id: string, user: any) {
this.logger.log('**** registerNym called...');
const payload = { id, user };
return this.sendNats(this.agentServiceProxy, 'register-nym-org', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'register-nym-org', payload);
}

restartStopAgent(action: string, orgId: string) {
const payload = { action, orgId };
return this.sendNats(this.agentServiceProxy, 'restart-stop-agent', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'restart-stop-agent', payload);
}

getAgentServerStatus(user) {

return this.sendNats(this.agentServiceProxy, 'get-agent-server-status', user);
return this.natsClient.sendNats(this.agentServiceProxy, 'get-agent-server-status', user);
}

pingServiceAgent() {
this.logger.log('**** pingServiceAgent called...');
const payload = {};
return this.sendNats(this.agentServiceProxy, 'ping-agent', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'ping-agent', payload);
}

agentSpinupStatus(items_per_page: number, page: number, search_text: string, agentStatus: string, sortValue: string, user: any) {
this.logger.log('**** agentSpinupStatus called...');
const payload = { items_per_page, page, search_text, agentStatus, sortValue, user };
return this.sendNats(this.agentServiceProxy, 'get-agent-spinup-status', payload);
return this.natsClient.sendNats(this.agentServiceProxy, 'get-agent-spinup-status', payload);
}
}
Loading