This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24815|Reply: 1

[ASP.NET] ASP.NET Core Link Tracing (3) SkyAPM is based on Consul dynamic configuration

[Copy link]
Posted on 2020-11-11 16:13:50 | | | |
Review:

ASP.NET Core Link Tracing (1) Install the Skywalking tutorial
https://www.itsvse.com/thread-9456-1-1.html

ASP.NET Core link tracing (2) uses SkyAPM integration
https://www.itsvse.com/thread-9458-1-1.html



project, you can use itConsulorApolloTo do the configuration center, a tutorial on Consul as a ASP.NET Core configuration center:

Architecture: ASP.NET Core dynamically configures hot updates based on Consul
https://www.itsvse.com/thread-9421-1-1.html
Requirements: We store the configuration information of APM in the Consul middleware, so we don't have to log in to the server to manually modify the configuration information in the appsettings.json file.

Start Consul

Start the consul middleware by first using the following command:




Install Consul related plugins ASP.NET Core

In our sky-apm-demo project, use nuget to install the Consul middleware as a plugin for reading the configuration center with the following command:

Modify the CreateHostBuilder method in the Program object to add the reading of remote Consul configuration information, the code is as follows:

Meanwhile, in the appsettings.json file, you need to configure the consul_url address, as follows:



Add our configuration information to consul to open the web management platform:The hyperlink login is visible.to create sky-apm-demo/appsettings. Development.json key, the value is as follows:



Create a new test3 controller method to read the information of our consul service configuration for easy testing, as follows:

AccessThe hyperlink login is visible.You can get the configuration we set normally, as follows:



Looking at the skyapm-20201111.log logs, you will find that the address where SkyApm accesses Skywalking is not what we configured, butDefault: localhost:11800, as shown in the figure below:



2020-11-11 15:32:35.869 +08:00 [My_Service] [Information] SkyApm.Transport.Grpc.ConnectionManager : Shutdown connection[localhost:11800].
2020-11-11 15:32:45.875 +08:00 [My_Service] [Error] SkyApm.Transport.Grpc.ConnectionManager : Connect server timeout.
System.Threading.Tasks.TaskCanceledException: Reached deadline.
   at Grpc.Core.Channel.WaitForStateChangedAsync(ChannelState lastObservedState, Nullable`1 deadline)
   at Grpc.Core.Channel.ConnectAsync(Nullable`1 deadline)
   at SkyApm.Transport.Grpc.ConnectionManager.ConnectAsync()
We check the SkyAPM.Agent.AspNetCore source code on GitHub and find that if our program assigns the default settings first, and then reads the configuration file appsettings.json skywalking.json skyapm.json to override the previous default values, as shown in the figure below:



Regarding the configuration, the loading process is as follows:



So when did SkyAPM establish communication with Skywalking?



The SkyAPM source code has an InstrumentationHostedService background task, when registering IHostedService,.NET Core calls the StartAsync() and StopAsync() methods of type IHostedService, respectively, during application start and stop

You can refer to:

A service based on .NET Core on Linux
https://www.itsvse.com/thread-9447-1-1.html
The problem now is that the configuration information set by our consul is overwritten by the default value of SkyAPM, and to solve this problem, we need to modify the source code, we download the SkyAPM source code on GitHub.

Modify the ConfigurationFactory file as follows:

Modify the ConfigurationBuilderExtensions file as follows:

For the modified source code, you can refer to my branch:The hyperlink login is visible.

Added logical judgment, when the SkyAPM configuration already exists, does not use the default value,Regeneratesky-apm-demo and SkyApm.Agent.AspNetCore projects, copy all the files under the modified library \src\SkyApm.Agent.AspNetCore\bin\Debug\netcoreapp3.1 folder to our project \bin\Debug\netcoreapp3.1 and replace them.Refresh your browser

By looking at the apm logs, you can find that the configuration information in consul has been successfully read and communication with Skywalking has been successfully established, as shown in the figure below:




(End)




Previous:. .NET MySQL Connector Conflicts DbProviderFactories (.NET MySQL Connector Conflicts DbP...
Next:.NET Core displays registered services and implementations and their lifecycles
Posted on 2023-6-2 14:24:31 |
Good sticker
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com