-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract all data acquisition from ResourceService (#1288)
* Extract all data acquisition from ResourceService This creates a new class `KubernetesDataSource` that encapsulates all code related to obtaining data from kubernetes in the `ResourceService`. This cleans the service code up a lot and makes the responsibilities clearer. The use of `Channel<ResourceChange>` has been removed. Instead, code invocations are made directly, skipping queuing. We still have two other channels that ensure front/back are decoupled. The kubernetes channel will ultimately also be removed, leaving just a channel for the subscriber. Added some API docs. * Check cancellation token * Remove Channel<T> for kubernetes objects This is the second removal of a `Channel<T>` from this component. Now, updates are passed by direct code invocations, skipping queuing. We still have a downstream channel for the subscriber to decouple front/back. * Inline method * Rename ResourceCollection to ResourcePublisher * Simplify inclusion of docker environment A few changes here: - Use more consistent names throughout. They're not "extra" or "additional" arguments. In fact they are a complete replacement. In their absence, the "spec" environment is used. - Move creation of docker inspection task to view model method, making the various "handle * update" methods more uniform, for future refactoring. - Remove special handling in `ProcessKubernetesChange` for one scenario. Simplifies the signature, and the code a fair bit. * Specify list capacity * Merge ObjectChangeType Add and Modified We only need to know if the value is "upserted" (updated or inserted), or "deleted". Recent changes to threading/queuing in the code here changed some timing. The arrival of one kind of resouce can trigger the publication of another, and these would always be "modified", however they could arrive before that resource's stream published that instance. The rest of the code handles these happening out-of-order. We just need to treat add and modified the same way, so they've been merged. * Use semaphore to serialize kubernetes data processing There are multiple kubernetes resource types, each with its own monitoring stream. Across these resources, updates arrive concurrently. The update flows for each type of resource can interact with state stored for other resources. Therefore we use a semaphore to ensure that only one resource update can flow through the system at a time. Another option would have been to make the collections concurrent, or use explicit locking. Concurrent collections are heavy. Explicit locking is tricky to get right. This mutual exclusion via top-level semaphore seems like a safe and elegant approach for now. * Avoid redundant linear scans When this method is passed the same collection twice, the `FromSpec` value will always be true, because every item in the list is in the list. Instead we pass `null` and consider all items as from the spec. * Simplify delegation of projects-as-executables * Avoid switch on every update Each instance of `WatchKubernetesResource<T>` produces a single type, that would flow through `ProcessKubernetesChange` to look up the relevant handler. Instead, pass the handler in to `WatchKubernetesResource<T>` so it can be invoked directly. * Formatting * Rename class to avoid name conflict This object is a snapshot of a service's state, not a service itself. We have another class which is a service. Append "Snapshot" to differentiate. Future work will extend this concept of snapshots more broadly. * Replace O(N) scanning with O(1) lookup * Make resource Endpoints and Services immutable * Make ResourceViewModel.Environment immutable Note that it's just the collection that becomes immutable here. The elements are still currently mutable. That will change when we split front/back ends, and have a snapshot on the backend with a view model on the front end. * Make ContainerViewModel Ports and Args immutable * Make ExecutableViewModel Arguments immutable * Make remaining scalar ExecutableViewModel properties immutable * Make all resource snapshot properties required * Add API docs for resource snapshot types * Rename KubernetesDataSource to DcpDataSource * Use collection literals for empty collections * Source container variables from status This data is now available from DCP, so we don't have to launch processes to query docker for this data any more, which simplifies things quite nicely. * Allocate less memory in ProcessUtil * Extract duplicate code * Further deduplicate code * Make ProjectViewModel derive from ExecutableViewModel * Remove duplicate razor after consolidating types * Merge project/executable snapshot construction Now that project snapshots derive from executable snapshots, we can unify a bunch of construction logic. * Replace O(N) scanning with O(1) lookup * Reorder methods * Start using "snapshot" naming in DCP data source We still have some types named ViewModel, but they'll be renamed later in the split. * Rename ObjectChangeType to ResourceChangeType It's not clear what object the name refers to, so make it more specific. It's internal, so we can always rename it again later. This name pairs nicely with `ObjectChange` too. * Further consolidate data processing The methods that handle executable and container updates are largely the same. Extract that commonality to a new method.
- Loading branch information
1 parent
818ac20
commit 1f56e60
Showing
20 changed files
with
558 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Aspire.Dashboard.Model; | ||
|
||
/// <summary> | ||
/// Immutable snapshot of executable state at a point in time. | ||
/// </summary> | ||
public class ExecutableViewModel : ResourceViewModel | ||
{ | ||
public override string ResourceType => "Executable"; | ||
public int? ProcessId { get; init; } | ||
public string? ExecutablePath { get; set; } | ||
public string? WorkingDirectory { get; set; } | ||
public List<string>? Arguments { get; set; } | ||
|
||
public required int? ProcessId { get; init; } | ||
public required string? ExecutablePath { get; init; } | ||
public required string? WorkingDirectory { get; init; } | ||
public required ImmutableArray<string>? Arguments { get; init; } | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Aspire.Dashboard.Model; | ||
|
||
public enum ResourceChangeType | ||
{ | ||
Other, | ||
|
||
/// <summary> | ||
/// The object was added if new, or updated if not. | ||
/// </summary> | ||
Upsert, | ||
|
||
/// <summary> | ||
/// The object was deleted. | ||
/// </summary> | ||
Deleted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.