digikare / nestjs-prom

A prometheus module for nestjs
160 stars 54 forks source link

Nest can't resolve dependencies of the TestService (?, ControlAndReportApiService). Please make sure that the argument at index [0] is available in the ControlAndReportModule context. #19

Closed RakhiSehrawat closed 4 years ago

RakhiSehrawat commented 4 years ago

[Nest] 26184 - 01/14/2020, 3:24:49 PM [ExceptionHandler] Nest can't resolve dependencies of the TestService (ControlAndReportApiService, ?). Please make sure that the argument at index [1] is available in the ControlAndReportModule context. +2ms Error: Nest can't resolve dependencies of the TestService (ControlAndReportApiService, ?). Please make sure that the argument at index [1] is available in the ControlAndReportModule context. at Injector.lookupComponentInExports (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:183:19) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Injector.resolveComponentInstance (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:143:33) at async resolveParam (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:96:38) at async Promise.all (index 1) at async Injector.resolveConstructorParams (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:112:27) at async Injector.loadInstance (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:78:9) at async Injector.loadProvider (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\injector.js:35:9) at async Promise.all (index 4) at async InstanceLoader.createInstancesOfProviders (D:\nestjs-prom-master\provision-alerter\node_modules@nestjs\core\injector\instance-loader.js:41:9)

Current behavior Whenever I do npm run start it gives me the above error and I am using the below code.

I followed the ReadMe instructions to used the digikare/nestjs-prom library into our project. I added the following: In app.module.ts : @module({ imports: [ PromModule.forRoot({ defaultLabels: { app: 'provision_alerter', }, customUrl: 'order/metrics' }),]

In test.module.ts:

@module({ imports:[ PromModule.forMetrics([ { type: MetricType.Counter, configuration: { name: 'index_counter', help: 'get count of test orders', } }]), ], providers:[TestService, ControlAndReportApiService], controllers:[TestController] }) export class TestModule{}

In test.service.ts:

constructor(private readonly controlAndReportApiService: ControlAndReportApiService, @InjectCounterMetric('index_counter') private readonly _counterMetric: CounterMetric, ) { }

async findTestOrders(): Promise<Order[]> {

const testOrders: Order[] = await getTestOrders();

this._counterMetric.inc(testOrders.length, new Date());

return testOrders;

}

Can someone please help me with this issue and let me know in case I am missing out something here?

RakhiSehrawat commented 4 years ago

This issue was resolved. There was a missing import in one of the modules. Once added stopped getting the above issue.