Open lklein53 opened 1 year ago
I've run into a similar issue today and am proposing a (maybe naive ?) fix here: https://github.com/npgsql/npgsql/pull/5497
I'd like to see that change, too.
I have another case of reproducing the problem. It reproduces on both the current version of the library and the version with the fix from #5497.
Case in project.
Reproduction Steps:
Npgsql.NpgsqlEventSource
class.DataSourceCreated
and OnEventCommand
methods.Expected result:
The execution thread first stopped in the DataSourceCreated
method, then moved to OnEventCommand
, idle-connections and busy-connections metrics were registered.
Factual result (both with and without the fix from https://github.com/npgsql/npgsql/pull/5497):
The execution thread stops in the OnEventCommand
method, then stops in the DataSourceCreated
method. It does not come to OnEventCommand
anymore, so after _dataSources
initiation there is no re-registration of metrics collection, because OnEventCommand
is not called again.
Also in the NpgSqlMeter
class you can put a breakpoint in the SaveMeasurements
method to see what metrics values are written to _values
. There are no values related to idle-connections and busy-connections.
FYI @elafarge
Hi together,
We are using the
Npgsql.DependencyInjection
to inject aNpgsqlDataSource
into the ServiceCollection. With this approach the event counter for idle and busy connections are missing and the number of connection pools is 0.Steps to reproduce
Use the
Npgsql.DependencyInjection
package and usebuilder.Services.AddNpgsqlDataSource("Host=pg_server;Username=test;Password=test;Database=test");
to inject aNpgsqlDataSource
. Use this data source to create a connection and collect the metrics viadotnet counters monitor Npgsql -p <PID>
The issue
We noticed that the EventCounter for
Idle Connections
,Busy Connections
are missing and that the counter forConnection Pools
is always 0.Further technical details
I think the issue is that
NpgsqlEventSource.Log.DataSourceCreated(newDataSource);
is only called fromSetupDataSource
and not from theNpgsqlDataSourceBuilder
.Thanks for your help and kind regards, Lars