blushingpenguin / mongodb.applicationinsights Goto Github PK
View Code? Open in Web Editor NEWAdds application insights tracking into MongoDB in an easy to use way.
License: Other
Adds application insights tracking into MongoDB in an easy to use way.
License: Other
Hi
We've been using this library for years with our classic Atlas cluster, but since switching to an Atlas Serverless cluster, we've started seeing intermittent timeout exceptions:
MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
---> System.TimeoutException: The operation has timed out.
at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(CancellationToken cancellationToken)
The application is an Azure App Service, and the pattern of failures is that all requests succeed until there's a period of idling, after which the next one will timeout.
At first, I didn't consider the possibility that it had anything to do with this library, so I reached out to the MongoDB Atlas team and wondered if they are aware of any issues related to slow cold starts or similar. But they suggested that I try and see if I can reproduce it when creating a MongoClient
directly without using this library, so for the last couple of days, I've been switching back and forth and I can indeed confirm that the timeouts only occur when this library is used.
Do you have any clue why this would happen?
Hi! Does it have support for the Azure Application Map for different slots?
When I use on an App Service that has Production Slot and Development Slot the request log can not differentiate between both. It seems like I', always using the Production Slot.
In the picture, the PRD communicates with MongoDB but the truth is that DEV does.
Thanks!
Hello there,
Last week we released a new version of one of our services with this library to get more info about the usage of MongoDB. This apps runs in our kubernetes cluster and our MongoDB is a mongodb as a service. We didn't see any problems at first, everything apparently was working as intended. After a while I notice that this service was OOMKilled a lot of times during the week after the release (in simple terms, the container was rebooted because it used more memory than we allowed it to have). So we put the threshold bigger, and today, for our surprise we got notified by MongoDB that our connection limit reached 80% of the limit, than after some minutes close to 100%. Only thing we did in this deploy was to add this library to help us with the Application Insights metrics.
So here are some charts that I got from the MongoDB. You can see that from 12 of setember there was a peak of commands with is followed with peak of connections:
The pikes and the valleys is because as the connections go up, memory consumption goes up, than the pod is killed and restarted, than goes again. Each chart is from one server in our replica set. After we removed the use of library:
So, this is the expected number of connections, we don't have a huge MongoDb use yet, these ones are shared instances since it's cheaper and it's ok for us.
I checked the library implementation and didn't find any reason for this, so maybe the way we are configuring it is wrong. This is what we have configured:
.AddSingleton<IMongoClientFactory>(
sp => new MongoClientFactory(
sp.GetService<TelemetryClient>(),
new MongoApplicationInsightsSettings()
))
We use repository pattern and all references are used as AddScoped
. If needed I can post all. We use this IMongoClientFactory
in our MongoDatabaseProvider
(we need the SslProtocols.Tls12
to connect to mongo):
namespace Some.NameSpace
{
using System;
using System.Security.Authentication;
using Configuration;
using global::MongoDB.Driver;
// this class is added as scoped
public class MongoDatabaseProvider : IDataBaseProvider<IMongoDatabase>
{
public MongoDatabaseProvider(IMongoDbSettings settings, IMongoClientFactory mongoClientFactory)
{
this.Settings = settings ?? throw new ArgumentNullException(nameof(settings));
if (!settings.UseSsl)
{
this.Client = new MongoClient(settings.ConnectionString);
}
else
{
var mongodbSettings = MongoClientSettings.FromUrl(
new MongoUrl(settings.ConnectionString)
);
mongodbSettings.SslSettings = new SslSettings { EnabledSslProtocols = SslProtocols.Tls12 };
// this factory already tests if there is application insights configuration
this.Client = mongoClientFactory?.GetClient(mongodbSettings) ?? new MongoClient(mongodbSettings);
}
}
private IMongoClient Client { get; }
private IMongoDbSettings Settings { get; }
public IMongoDatabase GetDatabase()
{
return this.Client.GetDatabase(this.Settings.Database);
}
}
}
Can someone have a look if we did something wrong? Maybe we cant register the factory as singleton?
Aquascaner has reported some issues due to this library ( MongoDB.ApplicationInsights ) dependency on NETStandard.Library 1.6.1
┌────────────────────────────────┬───────────────┬──────────┬───────────────────┬───────────────┬───────────────────────────────────────────────────────────┐
│ Library │ Vulnerability │ Severity │ Installed Version │ Fixed Version │ Title │
├────────────────────────────────┼───────────────┼──────────┼───────────────────┼───────────────┼───────────────────────────────────────────────────────────┤
│ System.Net.Http │ CVE-2018-8292 │ HIGH │ 4.3.0 │ 4.3.4 │ .NET Core: information disclosure due to authentication │
│ │ │ │ │ │ information exposed in a redirect... │
│ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2018-8292 │
├────────────────────────────────┼───────────────┤ │ ├───────────────┼───────────────────────────────────────────────────────────┤
│ System.Text.RegularExpressions │ CVE-2019-0820 │ │ │ 4.3.1 │ dotnet: timeouts for regular expressions are not enforced │
│ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2019-0820 │
└────────────────────────────────┴───────────────┴──────────┴───────────────────┴───────────────┴───────────────────────────────────────────────────────────┘
I am not sure how to solve this issue, because all versions of netstartard depends on a vulnerable version of the packages.
Currently the MongoDB.ApplicationInsights is overriding clientSettings.ClusterConfigurator so that calling application is not able to subscribe to Mongo DB events.
See #8 for fix.
P.S: build is failing with
HTTP 400
Provided token is not a UUID.
Command executed with exception:
when uploading data to https://codecov.io/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.