Skip to content

Commit

Permalink
Fix allowed Argo parameter list and logging scope data not being rend…
Browse files Browse the repository at this point in the history
…ered correctly (#870)

* Fix argo parameter validation keys.
Fix to correctly serialize logger scope values.

Signed-off-by: Victor Chang <[email protected]>

* Fix unit tests
Change argo pod date time to use the universal full ("U") format specifier


Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp authored Sep 5, 2023
1 parent 3cababe commit 0aca28d
Show file tree
Hide file tree
Showing 22 changed files with 195 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@
* limitations under the License.
*/

namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.StaticValues
using System.Collections.Generic;

namespace Monai.Deploy.WorkflowManager.Common.Configuration
{
internal static class Keys
public static class ArgoParameters
{
public struct ResourcesKey
{
public string TaskKey { get; set; }
public string ArgoKey { get; set; }
}
public static class ResourcesKeys
{
public static readonly ResourcesKey GpuLimit = new() { TaskKey = GpuRequired, ArgoKey = "nvidia.com/gpu" };

public static readonly ResourcesKey MemoryLimit = new() { TaskKey = Memory, ArgoKey = "memory" };

public static readonly ResourcesKey CpuLimit = new() { TaskKey = Cpu, ArgoKey = "cpu" };
}
/// <summary>
/// Key for the namespace where the Argo workflows are stored and executed.
/// </summary>
Expand Down Expand Up @@ -76,18 +91,33 @@ internal static class Keys
/// <summary>
/// Key for resource limitations
/// </summary>
public static readonly string ArgoResource = "resources";
public static readonly string Resources = "resources";

/// <summary>
/// Key for resource limitations
/// </summary>
public static readonly string ArgoParameters = "parameters";
public static readonly string Parameters = "parameters";

/// <summary>
/// Key for priority classnames on task plugin arguments side
/// </summary>
public static readonly string TaskPriorityClassName = "priority";

/// <summary>
/// Key for the CPU.
/// </summary>
public static readonly string Cpu = "cpu";

/// <summary>
/// Key for the memory.
/// </summary>
public static readonly string Memory = "memory";

/// <summary>
/// Key for the GPU.
/// </summary>
public static readonly string GpuRequired = "gpu_required";

/// <summary>
/// Required arguments to run the Argo workflow.
/// </summary>
Expand All @@ -96,6 +126,30 @@ internal static class Keys
WorkflowTemplateName
};

/// <summary>
/// Required arguments to run the Argo workflow.
/// </summary>
public static readonly IReadOnlyList<string> VaildParameters =
new List<string> {
Namespace,
BaseUrl,
AllowInsecureseUrl,
WorkflowTemplateName,
TimeoutSeconds,
ArgoApiToken,
MessagingEndpoint,
MessagingUsername,
MessagingPassword,
MessagingExchange,
MessagingVhost,
Resources,
Parameters,
TaskPriorityClassName,
Cpu,
Memory,
GpuRequired,
};

/// <summary>
/// Required settings to run the Argo workflow.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/Common/Miscellaneous/LoggingDataDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021-2023 MONAI Consortium
* Copyright 2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Globalization;
using System.Runtime.Serialization;

namespace Monai.Deploy.WorkflowManager.Common.Miscellaneous
{
[Serializable]
public class LoggingDataDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TKey : notnull
{
public LoggingDataDictionary()
{
}

protected LoggingDataDictionary(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public override string ToString()
{
var pairs = this.Select(x => string.Format(CultureInfo.InvariantCulture, "{0}={1}", x.Key, x.Value));
return string.Join(", ", pairs);
}
}
}
33 changes: 0 additions & 33 deletions src/Common/Miscellaneous/ValidationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@ public static class ValidationConstants
/// </summary>
public static readonly string Notifications = "notifications";

/// <summary>
/// Key for the CPU.
/// </summary>
public static readonly string Cpu = "cpu";

/// <summary>
/// Key for the memory.
/// </summary>
public static readonly string Memory = "memory";

/// <summary>
/// Key for the GPU.
/// </summary>
public static readonly string GpuRequired = "gpu_required";

/// <summary>
/// Key for recipient emails.
/// </summary>
Expand Down Expand Up @@ -107,24 +92,6 @@ public enum NotificationValues
Mode
};

/// <summary>
/// Key for the endpoint where the Argo server is running.
/// </summary>
public static readonly string BaseUrl = "server_url";

/// <summary>
/// Key for the name of the main 'WorkflowTemplate' stored on the targeted Argo server.
/// </summary>
public static readonly string WorkflowTemplateName = "workflow_template_name";

/// <summary>
/// Required arguments to run the Argo task args.
/// </summary>
public static readonly IReadOnlyList<string> ArgoRequiredParameters =
new List<string> {
BaseUrl,
WorkflowTemplateName
};


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void ValidateEventAndInit()

public override async Task<ExecutionStatus> ExecuteTask(CancellationToken cancellationToken = default)
{
using var loggingScope = _logger.BeginScope(new Dictionary<string, object>
using var loggingScope = _logger.BeginScope(new LoggingDataDictionary<string, object>
{
["correlationId"] = Event.CorrelationId,
["workflowInstanceId"] = Event.WorkflowInstanceId,
Expand Down
Loading

0 comments on commit 0aca28d

Please sign in to comment.