Closed ggnaegi closed 1 year ago
Nice PR, Guillaume! πΈ
You forgot to request my review. π And I will review in a couple of work days...
@raman-m I can't add you as a reviewer...
@raman-m Just checked the changes (with lock) in a docker container. It works
If you don't mind, I will make some code readability improvements...
What do you mean? Maybe in the future an editorconfig file would help? https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022
What do you mean? Maybe in the future an editorconfig file would help? Docs: Create portable, custom editor settings with EditorConfig
Interesting Visual Studio feature, but not now!
I meant the improvements in your code to read. Not in entire project! π€£ You will see...
I meant the improvements in your code to read. Not in entire project! π€£ You will see...
Ok, but, in general, it would be a nice addition.
@raman-m So, I thought we could do the same with the kubernetes provider factory, like Eureka and Consul...
@raman-m So, I thought we could do the same with the kubernetes provider factory, like Eureka and Consul...
Yes, we could! It seems I have to review once again... π«
@raman-m commented on Jun 28
π Yeah, sorry about this. I just modified that bit, since it seems logical to me, that the "getter logic" should be applied everywhere.
@raman-m Hello, it's done...
@ggnaegi commented on June 27, 2023
Why not to update the Service Discovery docs? π
I guess we need to:
Any ideas are welcome!
Why not to update the Service Discovery docs? π
Yeah, well. Let's say, we merge this PR and then I will create a new PR for the docs, OK?
Not OK! All PRs in this repo come with docs updating too! Tom points to updating docs always while reviewing a PR. It is better to add docs before asking him to review and merge. See example: #1655 where Tom asked to update docs.
If you don't know how to update docs, no worries, I will help you. Maybe today, maybe during this weekend...
Happy Friday!
Not OK! All PRs in this repo come with docs updating too!
It was a rhetorical question then π
Yeah so I will update the docs during the week-end.
@raman-m commented on Jun 30
Ha-ha! I said "Happy Friday" 3 months ago... π It is time, this autumn, to say once again: Happy Friday, Guillaume! π€£
Sorry, I was sooo busy with open PRs reviewing, conflicts resolutions, and getting ready them for real code reviews. π« Now I am back to your PR... π
@ggnaegi has invited you to collaborate on this repository.
Wow! π Thank you! But it is expired!
Is everything OK with your feature branch? Is it rebased onto develop?
The feature branch has been rebased onto develop! Please, pull commits!
FrΓΆhlichen Freitag! :bowtie:
Hi @raman-m, Sorry, I forgot to write the documentation. I was a bit frustrated with the current situation, so I started my own PoC with YARP, OIDC and Consul here : https://github.com/ggnaegi/SwizlyPeasy.Gateway
@ggnaegi commented on Sep 16
Sad hearing that you moved to Yarp instead of Ocelot. But I understand your decision. Ocelot is deprecated, and Tom as an owner, doesn't care about this project. I will return to you with some news in a couple of weeks...
Regarding documentation... Don't worry, I will update docs during my own code review... Updating docs requires focusing on source code to understand proposed changes and how it should be reflected to developer's documentation.
Welcome to code review!
@ggnaegi added 2 commits on Sep 16
What have you merged? I cannot get it... Ghost merge-commits have no sense.
That's bad!
@raman-m I just pulled the changes as you wrote and then this happened... That was a bit odd, since the same commits were shown twice. Should I have done git pull --rebase ?
Please make linear history! How, it is up to you.
@ggnaegi commented on Sep 16
Sad hearing that you moved to Yarp instead of Ocelot. But I understand this decision. Ocelot is deprecated, and Tom as an owner, doesn't care about this project. I will return to you with some news in a couple of weeks...
@raman-m Tom could at least write somewhere that the project is deprecated and that it's only maintained for security reasons. I read an article about ocelot on linkedin two weeks ago! You still have a strong developer base but no support and no improvements on some buggy features. It's a sad thing. I was happy with Ocelot but it's not an option anymore...
@ggnaegi
Tom could at least write somewhere that the project is deprecated and that it's only maintained for security reasons.
Where? And how? Ocelot community tells that every day... ))
I read an article about ocelot on LinkedIn two weeks ago!
Could you share the link plz? Who is the author?
You still have a strong developer base but no support and no improvements on some buggy features. It's a sad thing. I was happy with Ocelot but it's not an option anymore...
You did the right thing because other gateway products just evolute having regular releases.
Anyway, hope that you will return to this project to contribute...
@ggnaegi commented on Sep 18, 11:32
Are you going to fix the problem? Can I help you?
Should I have done git pull --rebase ?
Yes, please! If you have time...
@raman-m
I read an article about ocelot on LinkedIn two weeks ago!
Could you share the link plz? Who is the author?
Yes sure: JOVANOVIC Milan: https://www.linkedin.com/posts/milan-jovanovic_softwareengineering-dotnet-microservices-activity-7015949109593309184-Ssxx DOKIC Stefan: https://lnkd.in/dCmEkCNP
@ggnaegi commented on Sep 18, 11:32
Are you going to fix the problem? Can I help you?
Should I have done git pull --rebase ?
Yes, please! If you have time...
@raman-m should be fine now. Should I also commit the changes suggested by @RaynaldM?
@ggnaegi commented on Sep 18, 13:30
Already Done! See https://github.com/ThreeMammals/Ocelot/pull/1670/commits/b3f1d551c150967f9fc2178fd5839fc77c841e05
@ggnaegi commented on Sep 18, 13:30
Already Done! See b3f1d55
@raman-m, ok, that's another perspective... I just got your point. But still, we could have: public const string PollKube = nameof(PollKube);
@ggnaegi We could, but it references to itself: Technically we can change.
@raman-m commented on Sep 18, 13:41
Let's keep it as it is in https://github.com/ThreeMammals/Ocelot/commit/b3f1d551c150967f9fc2178fd5839fc77c841e05, ok?
@raman-m I just had a look at the Eureka and Kubernetes providers... IMHO, we could modify them, because PollKube is using the same Timer-Logic as PollConsul did...
@ggnaegi Ocelot.AcceptanceTests.ConfigurationReloadTests.should_trigger_change_token_on_change Please, fix the failed test! Something was changed and this test must be reviewed. It fails locally too.
P.S. I've rebased feature branch. Don't pull, because pull can have auto-merge enabled. Just do:
git fetch --all
git checkout ggnaegi:bug/polling-consul
In this case, I hope, there will be no auto-merge commits. Don't forget to Sync fork π There is new commit for develop branch.
@ggnaegi Ocelot.AcceptanceTests.ConfigurationReloadTests.should_trigger_change_token_on_change Please, fix the failed test! Something was changed and this test must be reviewed. It fails locally too.
@raman-m I should check, Xunit is running the tests in parallel, it might cause the problems.
@raman-m Ok, tests are passing now (2161db0). But you might have a problem somewhere else. Look at the job on the main branch, it failed: https://app.circleci.com/pipelines/github/ThreeMammals/Ocelot/857/workflows/cf2a0f20-4d12-4515-a251-c00a418f5259/jobs/1592
@raman-m I just had a look at the Eureka and Kubernetes providers... IMHO, we could modify them, because PollKube is using the same Timer-Logic as PollConsul did...
@raman-m Should I include the changes in this PR too, or later?
@ggnaegi commented on Sep 19:
@raman-m Ok, tests are passing now (2161db0).
Thanks for fixing it! I saw this fix in another PR that got stuck and wasn't delivered to develop branch. To be fair, I wondered why parallelization was not disabled for hard acceptance tests. Or we have some hidden setting in the project to disable XUnit parallelization... Anyway, it is nice to include to your PR...
Look at the job on the main branch, it failed: https://app.circleci.com/pipelines/github/ThreeMammals/Ocelot/857/workflows/cf2a0f20-4d12-4515-a251-c00a418f5259/jobs/1592
This failed build doesn't belong to your feature branch!!!
@ggnaegi commented on Sep 19:
Should I include the changes in this PR too, or later?
Did you mean fixing thread safety & starting errors for another types of providers? Well... This is beyond the scope of this feature, but... It will be very desirable to fix other service providers. In this case we must search for other open issues in backlog and link them to fix by this PR. But this is not trivial task... π
@ggnaegi commented on Sep 19:
Ok, tests are passing now (2161db0). But you might have a problem somewhere else. Look at the job on the main branch, it failed: Build 1592
So, I've created issue:
Could you create new PR for #1700 please? You will be the author of this fix. π PR creation will take 5 minutes, I guess... I would like to merge this fix ASAP on Monday...
@raman-m What should we do with this one?
@raman-m commented on Sep 19: Did you mean fixing thread safety & starting errors for another types of providers? Well... This is beyond the scope of this feature, but... It will be very desirable to fix other service providers. In this case we must search for other open issues in backlog and link them to fix by this PR. But this is not trivial task... π
I would create an new PR per Provider later, ok?
@raman-m @RaynaldM I might have a solution to generalize the "polling" for Consul, Kubernetes and Eureka... Should I push it, or would you like to merge first and then open a new PR?
using Ocelot.Logging;
using Ocelot.ServiceDiscovery.Providers;
namespace Ocelot.Polling;
public class PollingServicesManager<T, TU>
where T : class, IServiceDiscoveryProvider
where TU : ServicePollingHandler<T>
{
private readonly object _lockObject = new();
private readonly List<ServicePollingHandler<T>> _serviceDiscoveryProviders = new();
public ServicePollingHandler<T> GetServicePollingHandler(T baseProvider, string serviceName, int pollingInterval,
IOcelotLoggerFactory factory)
{
lock (_lockObject)
{
var discoveryProvider = _serviceDiscoveryProviders.FirstOrDefault(x => x.ServiceName == serviceName);
if (discoveryProvider != null)
{
return discoveryProvider;
}
discoveryProvider =
(TU)Activator.CreateInstance(typeof(TU), baseProvider, pollingInterval, serviceName, factory);
_serviceDiscoveryProviders.Add(discoveryProvider);
return (TU)discoveryProvider;
}
}
}
using Ocelot.Logging;
using Ocelot.ServiceDiscovery.Providers;
using Ocelot.Values;
namespace Ocelot.Polling;
public abstract class ServicePollingHandler<T> : IServiceDiscoveryProvider
where T : class, IServiceDiscoveryProvider
{
private readonly T _baseProvider;
private readonly object _lockObject = new();
private readonly IOcelotLogger _logger;
private readonly int _pollingInterval;
private DateTime _lastUpdateTime;
private List<Service> _services;
protected ServicePollingHandler(T baseProvider, int pollingInterval, string serviceName,
IOcelotLoggerFactory factory)
{
_logger = factory.CreateLogger<ServicePollingHandler<T>>();
_pollingInterval = pollingInterval;
// Initialize by DateTime.MinValue as lowest value.
// Polling will occur immediately during the first call
_lastUpdateTime = DateTime.MinValue;
_services = new List<Service>();
ServiceName = serviceName;
_baseProvider = baseProvider;
}
public string ServiceName { get; protected set; }
public Task<List<Service>> Get()
{
lock (_lockObject)
{
var refreshTime = _lastUpdateTime.AddMilliseconds(_pollingInterval);
// Check if any services available
if (refreshTime >= DateTime.UtcNow && _services.Any())
{
return Task.FromResult(_services);
}
_logger.LogInformation($"Retrieving new client information for service: {ServiceName}.");
_services = _baseProvider.Get().Result;
_lastUpdateTime = DateTime.UtcNow;
return Task.FromResult(_services);
}
}
}
using Ocelot.Logging;
using Ocelot.Polling;
namespace Ocelot.Provider.Consul;
public class PollConsul : ServicePollingHandler<Consul>
{
public PollConsul(Consul baseProvider, int pollingInterval, string serviceName, IOcelotLoggerFactory factory) : base(baseProvider, pollingInterval, serviceName, factory)
{
}
}
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration;
using Ocelot.Logging;
using Ocelot.Polling;
using Ocelot.ServiceDiscovery.Providers;
namespace Ocelot.Provider.Consul;
public static class ConsulProviderFactory
{
/// <summary>
/// String constant used for provider type definition.
/// </summary>
public const string PollConsul = nameof(Provider.Consul.PollConsul);
private static readonly PollingServicesManager<Consul, PollConsul> ServicesManager = new();
public static ServiceDiscoveryFinderDelegate Get { get; } = CreateProvider;
private static IServiceDiscoveryProvider CreateProvider(IServiceProvider provider,
ServiceProviderConfiguration config, DownstreamRoute route)
{
var factory = provider.GetService<IOcelotLoggerFactory>();
var consulFactory = provider.GetService<IConsulClientFactory>();
var consulRegistryConfiguration = new ConsulRegistryConfiguration(
config.Scheme, config.Host, config.Port, route.ServiceName, config.Token);
var consulProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);
if (PollConsul.Equals(config.Type, StringComparison.OrdinalIgnoreCase))
{
return ServicesManager.GetServicePollingHandler(consulProvider, route.ServiceName, config.PollingInterval, factory);
}
return consulProvider;
}
}
@ggnaegi commented on Sep 27, 1:38pm:
I might have a solution to generalize the "polling" for Consul, Kubernetes and Eureka... Should I push it, or would you like to merge first and then open a new PR?
Thank you for your intention to improve the code quality! But not in this PR please which is related to Consul services problems. Let's create a separate follow up PR, please... I am afraid this PR cannot be included into September's release if we have (will have) multiple review for a 3 month and more. Multiple code reviews makes delivery very slow. And, improvements for other service discovery providers can be included in October's release, not urgent. So, delivery of Consul improvements is very important in current upcoming release. The PR will close 6 issues! π»
@ggnaegi What are we waiting for? What is the rest of work?
@ggnaegi What are we waiting for? What is the rest of work?
I don't know, you said docs?
@raman-m so, first merge to develop then update the docs?
@ggnaegi commented: so, first merge to develop then update the docs?
No! First, Update feature branch by top commits from develop Second, Update docs by committing to feature branch Third, I will merge to develop
I believe you did everything for this PR if you cannot (don't know how) to review docs. I suggest you to focus on other PRs... Follow up PR for this one with refactoring other service providers (Eureka, etc.) Or, you can look into the bug #1706
I hope, this your PR will be updated & merged right today, because I've planned to work on it today.
P.S. And, don't forget to sync fork, update develop of your forked repo.
If you don't mind, I will make some improvements to the code...
@raman-m what do you mean by code improvements? We already had several reviews and changes... @raman-m You mean some missing braces? Yeah, ok, you could add them. I should modify my Resharper config.
Fixes #1634 #1487 #1329 #1304 #1294 #793
1634
1487
1329
1304
1294
793
Proposing some improvements for Consul "polling"
Proposed Changes
PollConsul
and in the factory.