Skip to content

Commit 04cb1ff

Browse files
committed
fix(Dashboard): used proper logger instead of console
Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
1 parent 43fac8b commit 04cb1ff

File tree

13 files changed

+115
-66
lines changed

13 files changed

+115
-66
lines changed

src/dashboard/Synapse.Dashboard/Components/DocumentDetails/Store.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ namespace Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1919
/// <summary>
2020
/// Represents the <see cref="ComponentStore{TState}" /> of a <see cref="DocumentDetails"/>
2121
/// </summary>
22+
/// <param name="logger">The service used to perform logging</param>
2223
/// <param name="apiClient">The service used interact with Synapse API</param>
2324
/// <param name="jsRuntime">The service used from JS interop</param>
2425
/// <param name="monacoEditorHelper">The service used ease Monaco Editor interactions</param>
2526
/// <param name="jsonSerializer">The service used to serialize and deserialize JSON</param>
2627
/// <param name="yamlSerializer">The service used to serialize and deserialize YAML</param>
2728
public class DocumentDetailsStore(
29+
ILogger<DocumentDetailsStore> logger,
2830
ISynapseApiClient apiClient,
2931
IJSRuntime jsRuntime,
3032
IMonacoEditorHelper monacoEditorHelper,
@@ -37,10 +39,16 @@ IYamlSerializer yamlSerializer
3739
private TextModel? _textModel = null;
3840
private readonly string _textModelUri = monacoEditorHelper.GetResourceUri();
3941

42+
/// <summary>
43+
/// Gets the service used to perform logging
44+
/// </summary>
45+
protected ILogger<DocumentDetailsStore> Logger { get; } = logger;
46+
4047
/// <summary>
4148
/// Gets the service used to interact with the Synapse API
4249
/// </summary>
4350
protected ISynapseApiClient ApiClient { get; } = apiClient;
51+
4452
/// <summary>
4553
/// Gets the service used for JS interop
4654
/// </summary>
@@ -192,8 +200,7 @@ public void SetDocument(object? document)
192200
}
193201
catch (Exception ex)
194202
{
195-
// todo: handle ex
196-
Console.WriteLine(ex.ToString());
203+
this.Logger.LogError("Unable to set document, exception: {exception}", ex.ToString());
197204
}
198205
}
199206
#endregion
@@ -273,8 +280,7 @@ public async Task LoadReferencedDocumentAsync()
273280
}
274281
catch (Exception ex)
275282
{
276-
Console.WriteLine(ex.ToString());
277-
// todo: handle exception
283+
this.Logger.LogError("Unabled to load referenced document: {exception}", ex.ToString());
278284
}
279285
}
280286

@@ -317,8 +323,7 @@ public async Task SetTextBasedEditorLanguageAsync()
317323
}
318324
catch (Exception ex)
319325
{
320-
Console.WriteLine(ex.ToString());
321-
// todo: handle exception
326+
this.Logger.LogError("Unabled to set text editor language: {exception}", ex.ToString());
322327
}
323328
}
324329

@@ -342,7 +347,7 @@ async Task SetTextEditorValueAsync()
342347
}
343348
catch (Exception ex)
344349
{
345-
Console.WriteLine(ex.ToString());
350+
this.Logger.LogError("Unabled to set text editor value: {exception}", ex.ToString());
346351
await this.MonacoEditorHelper.ChangePreferredLanguageAsync(language == PreferredLanguage.YAML ? PreferredLanguage.JSON : PreferredLanguage.YAML);
347352
}
348353
}

src/dashboard/Synapse.Dashboard/Components/MonacoEditor/Store.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,31 @@
1212
// limitations under the License.
1313

1414
using Synapse.Api.Client.Services;
15+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1516

1617
namespace Synapse.Dashboard.Components.MonacoEditorStateManagement;
1718

1819
/// <summary>
1920
/// Represents the <see cref="ComponentStore{TState}" /> of a <see cref="MonacoEditor"/>
2021
/// </summary>
22+
/// <param name="logger">The service used to perform logging</param>
2123
/// <param name="apiClient">The service used interact with Synapse API</param>
2224
/// <param name="jsRuntime">The service used from JS interop</param>
2325
/// <param name="monacoEditorHelper">The service used ease Monaco Editor interactions</param>
2426
/// <param name="jsonSerializer">The service used to serialize and deserialize JSON</param>
2527
/// <param name="yamlSerializer">The service used to serialize and deserialize YAML</param>
26-
public class MonacoEditorStore(ISynapseApiClient apiClient, IJSRuntime jsRuntime, IMonacoEditorHelper monacoEditorHelper, IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer)
28+
public class MonacoEditorStore(ILogger<MonacoEditorStore> logger, ISynapseApiClient apiClient, IJSRuntime jsRuntime, IMonacoEditorHelper monacoEditorHelper, IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer)
2729
: ComponentStore<MonacoEditorState>(new())
2830
{
2931

3032
TextModel? _textModel;
3133
string _textModelUri = monacoEditorHelper.GetResourceUri();
3234

35+
/// <summary>
36+
/// Gets the service used to perform logging
37+
/// </summary>
38+
protected ILogger<MonacoEditorStore> Logger { get; } = logger;
39+
3340
/// <summary>
3441
/// Gets the service used to interact with the Synapse API
3542
/// </summary>
@@ -214,7 +221,7 @@ public async Task ToggleTextBasedEditorLanguageAsync(string _)
214221
}
215222
catch (Exception ex)
216223
{
217-
Console.WriteLine(ex.ToString());
224+
this.Logger.LogError("Unabled to set text editor value: {exception}", ex.ToString());
218225
await this.MonacoEditorHelper.ChangePreferredLanguageAsync(language == PreferredLanguage.YAML ? PreferredLanguage.JSON : PreferredLanguage.YAML);
219226
}
220227
}
@@ -248,8 +255,7 @@ public async Task SetTextBasedEditorLanguageAsync()
248255
}
249256
catch (Exception ex)
250257
{
251-
Console.WriteLine(ex.ToString());
252-
// todo: handle exception
258+
this.Logger.LogError("Unabled to set text editor language: {exception}", ex.ToString());
253259
}
254260
}
255261

src/dashboard/Synapse.Dashboard/Components/ResourceEditor/Store.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Neuroglia.Data;
1616
using Neuroglia.Serialization.Yaml;
1717
using Synapse.Api.Client.Services;
18+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1819

1920
namespace Synapse.Dashboard.Components.ResourceEditorStateManagement;
2021

@@ -24,15 +25,21 @@ namespace Synapse.Dashboard.Components.ResourceEditorStateManagement;
2425
/// <remarks>
2526
/// Initializes a new <see cref="ResourceEditorStore{TResource}"/>
2627
/// </remarks>
28+
/// <param name="logger">The service used to perform logging</param>
2729
/// <param name="apiClient">The service used to interact with a Synapse API</param>
2830
/// <param name="monacoEditorHelper">The service used to facilitate the Monaco editor interactions</param>
2931
/// <param name="jsonSerializer">The The service used to serialize/deserialize objects to/from JSON</param>
3032
/// <param name="yamlSerializer">The service used to serialize/deserialize objects to/from YAML</param>
31-
public class ResourceEditorStore<TResource>(ISynapseApiClient apiClient, IMonacoEditorHelper monacoEditorHelper, IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer)
33+
public class ResourceEditorStore<TResource>(ILogger<ResourceEditorStore<TResource>> logger, ISynapseApiClient apiClient, IMonacoEditorHelper monacoEditorHelper, IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer)
3234
: ComponentStore<ResourceEditorState<TResource>>(new())
3335
where TResource : Resource, new()
3436
{
3537

38+
/// <summary>
39+
/// Gets the service used to perform logging
40+
/// </summary>
41+
protected ILogger<ResourceEditorStore<TResource>> Logger { get; } = logger;
42+
3643
/// <summary>
3744
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.Resource"/> changes
3845
/// </summary>
@@ -238,7 +245,7 @@ public async Task ChangeTextEditorLanguageAsync(string language)
238245
}
239246
catch (Exception ex)
240247
{
241-
Console.WriteLine(ex.ToString());
248+
this.Logger.LogError("Unabled to change text editor language: {exception}", ex.ToString());
242249
await monacoEditorHelper.ChangePreferredLanguageAsync(language == PreferredLanguage.YAML ? PreferredLanguage.JSON : PreferredLanguage.YAML);
243250
}
244251
}
@@ -287,7 +294,7 @@ public async Task CreateResourceAsync()
287294
}
288295
catch (Exception ex)
289296
{
290-
Console.WriteLine(ex.ToString()); // todo: improve logging
297+
this.Logger.LogError("Unable to create resource: {exception}", ex.ToString());
291298
}
292299
this.SetSaving(false);
293300
}
@@ -327,7 +334,7 @@ public async Task UpdateResourceAsync()
327334
}
328335
catch (Exception ex)
329336
{
330-
Console.WriteLine(ex.ToString()); // todo: improve logging
337+
this.Logger.LogError("Unable to update resource: {exception}", ex.ToString());
331338
}
332339
}
333340
this.SetSaving(false);

src/dashboard/Synapse.Dashboard/Components/ResourceManagement/ClusterResourceManagementComponentStore.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313

1414
using Synapse.Api.Client.Services;
15-
using System.Reactive.Linq;
15+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1616

1717
namespace Synapse.Dashboard.Components.ResourceManagement;
1818

@@ -23,10 +23,11 @@ namespace Synapse.Dashboard.Components.ResourceManagement;
2323
/// <remarks>
2424
/// Initializes a new <see cref="ClusterResourceManagementComponentStore{TResource}"/>
2525
/// </remarks>
26+
/// <param name="logger">The service used to perform logging</param>
2627
/// <param name="apiClient">The service used to interact with the Synapse API</param>
2728
/// <param name="resourceEventHub">The <see cref="IResourceEventWatchHub"/> websocket service client</param>
28-
public class ClusterResourceManagementComponentStore<TResource>(ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
29-
: ResourceManagementComponentStoreBase<TResource>(apiClient, resourceEventHub)
29+
public class ClusterResourceManagementComponentStore<TResource>(ILogger<ClusterResourceManagementComponentStore<TResource>> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
30+
: ResourceManagementComponentStoreBase<TResource>(logger, apiClient, resourceEventHub)
3031
where TResource : Resource, new()
3132
{
3233

@@ -64,8 +65,7 @@ public override async Task ListResourcesAsync(ResourcesFilter? filter = null)
6465
}
6566
catch (Exception ex)
6667
{
67-
Console.WriteLine(ex.ToString());
68-
// todo: implement proper error handling
68+
this.Logger.LogError("Unable to list resources, {exception}", ex.ToString());
6969
}
7070
}
7171

src/dashboard/Synapse.Dashboard/Components/ResourceManagement/NamespacedResourceManagementComponentStore.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313

1414
using Synapse.Api.Client.Services;
15+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1516
using System.Reactive.Linq;
1617

1718
namespace Synapse.Dashboard.Components.ResourceManagement;
@@ -21,10 +22,11 @@ namespace Synapse.Dashboard.Components.ResourceManagement;
2122
/// </summary>
2223
/// <typeparam name="TState">The type of the component's state</typeparam>
2324
/// <typeparam name="TResource">The type of <see cref="IResource"/>s to manage</typeparam>
25+
/// <param name="logger">The service used to perform logging</param>
2426
/// <param name="apiClient">The service used to interact with the Synapse API</param>
2527
/// <param name="resourceEventHub">The <see cref="IResourceEventWatchHub"/> websocket service client</param>
26-
public class NamespacedResourceManagementComponentStore<TState, TResource>(ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
27-
: ResourceManagementComponentStoreBase<TState, TResource>(apiClient, resourceEventHub)
28+
public class NamespacedResourceManagementComponentStore<TState, TResource>(ILogger<NamespacedResourceManagementComponentStore<TState, TResource>> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
29+
: ResourceManagementComponentStoreBase<TState, TResource>(logger, apiClient, resourceEventHub)
2830
where TResource : Resource, new()
2931
where TState : NamespacedResourceManagementComponentState<TResource>, new()
3032
{

src/dashboard/Synapse.Dashboard/Components/ResourceManagement/ResourceManagementComponentStoreBase.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313

1414
using Synapse.Api.Client.Services;
15+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1516

1617
namespace Synapse.Dashboard.Components.ResourceManagement;
1718

@@ -20,14 +21,20 @@ namespace Synapse.Dashboard.Components.ResourceManagement;
2021
/// </summary>
2122
/// <typeparam name="TState">The type of the state managed by the component store</typeparam>
2223
/// <typeparam name="TResource">The type of <see cref="IResource"/>s to manage</typeparam>
24+
/// <param name="logger">The service used to perform logging</param>
2325
/// <param name="apiClient">The service used to interact with the Synapse API</param>
2426
/// <param name="resourceEventHub">The <see cref="IResourceEventWatchHub"/> websocket service client</param>
25-
public abstract class ResourceManagementComponentStoreBase<TState, TResource>(ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
27+
public abstract class ResourceManagementComponentStoreBase<TState, TResource>(ILogger<ResourceManagementComponentStoreBase<TState, TResource>> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
2628
: ComponentStore<TState>(new())
2729
where TResource : Resource, new()
2830
where TState : ResourceManagementComponentState<TResource>, new()
2931
{
3032

33+
/// <summary>
34+
/// Gets the service used to perform logging
35+
/// </summary>
36+
protected ILogger<ResourceManagementComponentStoreBase<TState, TResource>> Logger { get; } = logger;
37+
3138
/// <summary>
3239
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceDefinition"/>s of the specified type
3340
/// </summary>
@@ -83,7 +90,7 @@ public abstract class ResourceManagementComponentStoreBase<TState, TResource>(IS
8390
/// Gets an <see cref="IObservable{T}"/> used to observe the <see cref="ResourcesFilter"/>
8491
/// </summary>
8592
protected virtual IObservable<ResourcesFilter> Filter => this.LabelSelectors
86-
.Select(labelSelectors => new ResourcesFilter() { LabelSelectors = labelSelectors })
93+
.Select(labelSelectors => new ResourcesFilter() { LabelSelectors = labelSelectors })
8794
.DistinctUntilChanged();
8895

8996
/// <summary>
@@ -127,15 +134,17 @@ public override async Task InitializeAsync()
127134
await this.GetResourceDefinitionAsync().ConfigureAwait(false);
128135
await this.ResourceEventHub.StartAsync().ConfigureAwait(false);
129136
this.ResourceWatch = await this.ResourceEventHub.WatchAsync<TResource>().ConfigureAwait(false);
130-
this.ResourceWatch.SubscribeAsync(
131-
onNextAsync: this.OnResourceWatchEventAsync,
132-
onErrorAsync: ex => Task.Run(() => Console.WriteLine(ex)),
133-
onCompletedAsync: () => Task.CompletedTask,
134-
cancellationToken: this.CancellationTokenSource.Token
135-
);
137+
this.ResourceWatch
138+
.Do(e => this.Logger.LogTrace("ResourceWatch received event '{type}' for '{name}'", e.Type.ToString(), e.Resource.GetName()))
139+
.SubscribeAsync(
140+
onNextAsync: this.OnResourceWatchEventAsync,
141+
onErrorAsync: ex => Task.Run(() => this.Logger.LogError("ResourceWatch exception: {exception}", ex.ToString())),
142+
onCompletedAsync: () => Task.CompletedTask,
143+
cancellationToken: this.CancellationTokenSource.Token
144+
);
136145
this.Filter.Throttle(TimeSpan.FromMilliseconds(10)).SubscribeAsync(
137146
onNextAsync: this.ListResourcesAsync,
138-
onErrorAsync: ex => Task.Run(() => Console.WriteLine(ex)),
147+
onErrorAsync: ex => Task.Run(() => this.Logger.LogError("Resource filter exception: {exception}", ex.ToString())),
139148
onCompletedAsync: () => Task.CompletedTask,
140149
cancellationToken: this.CancellationTokenSource.Token
141150
);
@@ -227,7 +236,7 @@ public virtual void ToggleResourceSelection(string? name = null)
227236
{
228237
if (string.IsNullOrWhiteSpace(name))
229238
{
230-
if (state.SelectedResourceNames.Any())
239+
if (state.SelectedResourceNames.Count > 0)
231240
{
232241
return state with
233242
{
@@ -268,7 +277,7 @@ public async Task DeleteSelectedResourcesAsync()
268277
{
269278
var selectedResourcesNames = this.Get(state => state.SelectedResourceNames);
270279
var resources = (this.Get(state => state.Resources) ?? []).Where(resource => selectedResourcesNames.Contains(resource.GetName()));
271-
foreach(var resource in resources)
280+
foreach (var resource in resources)
272281
{
273282
await this.DeleteResourceAsync(resource);
274283
}
@@ -313,8 +322,7 @@ public virtual async Task ListResourcesAsync(ResourcesFilter? filter = null)
313322
}
314323
catch (Exception ex)
315324
{
316-
Console.WriteLine(ex.ToString());
317-
// todo: implement proper error handling
325+
this.Logger.LogError("Unable to list resources: {exception}", ex.ToString());
318326
}
319327
}
320328

@@ -426,10 +434,11 @@ protected override async ValueTask DisposeAsync(bool disposing)
426434
/// <remarks>
427435
/// Initializes a new <see cref="ResourceManagementComponentStoreBase{TResource}"/>
428436
/// </remarks>
437+
/// <param name="logger">The service used to perform logging</param>
429438
/// <param name="apiClient">The service used to interact with the Synapse API</param>
430439
/// <param name="resourceEventHub">The <see cref="IResourceEventWatchHub"/> websocket service client</param>
431-
public abstract class ResourceManagementComponentStoreBase<TResource>(ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
432-
: ResourceManagementComponentStoreBase<ResourceManagementComponentState<TResource>, TResource>(apiClient, resourceEventHub)
440+
public abstract class ResourceManagementComponentStoreBase<TResource>(ILogger<ResourceManagementComponentStoreBase<TResource>> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
441+
: ResourceManagementComponentStoreBase<ResourceManagementComponentState<TResource>, TResource>(logger, apiClient, resourceEventHub)
433442
where TResource : Resource, new()
434443
{
435444

src/dashboard/Synapse.Dashboard/Pages/WorkflowInstances/List/Store.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313

1414
using Synapse.Api.Client.Services;
15+
using Synapse.Dashboard.Components.DocumentDetailsStateManagement;
1516
using Synapse.Dashboard.Pages.Workflows.List;
1617
using Synapse.Resources;
1718

@@ -20,10 +21,11 @@ namespace Synapse.Dashboard.Pages.WorkflowInstances.List;
2021
/// <summary>
2122
/// Represents the <see cref="View"/>'s store
2223
/// </summary>
24+
/// <param name="logger">The service used to perform logging</param>
2325
/// <param name="apiClient">The service used to interact with the Synapse API</param>
2426
/// <param name="resourceEventHub">The hub used to watch resource events</param>
25-
public class WorkflowInstanceListComponentStore(ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
26-
: NamespacedResourceManagementComponentStore<WorkflowInstanceListState, WorkflowInstance>(apiClient, resourceEventHub)
27+
public class WorkflowInstanceListComponentStore(ILogger<WorkflowInstanceListComponentStore> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
28+
: NamespacedResourceManagementComponentStore<WorkflowInstanceListState, WorkflowInstance>(logger, apiClient, resourceEventHub)
2729
{
2830

2931
/// <summary>

0 commit comments

Comments
 (0)