Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Track and report the "source" of a service. (#1124)
Browse files Browse the repository at this point in the history
* Track and report the "source" of a service.

* Update file encoding.
  • Loading branch information
philliphoff committed Jul 20, 2021
1 parent 3b5afa1 commit 4588079
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 34 deletions.
14 changes: 8 additions & 6 deletions src/Microsoft.Tye.Core/ApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F

if (!string.IsNullOrEmpty(configService.Project))
{
var project = new DotnetProjectServiceBuilder(configService.Name!, new FileInfo(configService.ProjectFullPath));
// TODO: Investigate possible null.
var project = new DotnetProjectServiceBuilder(configService.Name!, new FileInfo(configService.ProjectFullPath!), ServiceSource.Configuration);
service = project;

project.Build = configService.Build ?? true;
Expand Down Expand Up @@ -195,7 +196,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
}
else if (!string.IsNullOrEmpty(configService.Image))
{
var container = new ContainerServiceBuilder(configService.Name!, configService.Image!)
var container = new ContainerServiceBuilder(configService.Name!, configService.Image!, ServiceSource.Configuration)
{
Args = configService.Args,
Replicas = configService.Replicas ?? 1
Expand All @@ -207,7 +208,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
}
else if (!string.IsNullOrEmpty(configService.DockerFile))
{
var dockerFile = new DockerFileServiceBuilder(configService.Name!, configService.Image!)
var dockerFile = new DockerFileServiceBuilder(configService.Name!, configService.Image!, ServiceSource.Configuration)
{
Args = configService.Args,
Build = configService.Build ?? true,
Expand Down Expand Up @@ -241,7 +242,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
workingDirectory = Path.GetDirectoryName(expandedExecutable)!;
}

var executable = new ExecutableServiceBuilder(configService.Name!, expandedExecutable)
var executable = new ExecutableServiceBuilder(configService.Name!, expandedExecutable, ServiceSource.Configuration)
{
Args = configService.Args,
WorkingDirectory = configService.WorkingDirectory != null ?
Expand Down Expand Up @@ -310,7 +311,8 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F

var functionBuilder = new AzureFunctionServiceBuilder(
configService.Name,
azureFunctionDirectory)
azureFunctionDirectory,
ServiceSource.Configuration)
{
Args = configService.Args,
Replicas = configService.Replicas ?? 1,
Expand All @@ -332,7 +334,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
}
else if (configService.External)
{
var external = new ExternalServiceBuilder(configService.Name);
var external = new ExternalServiceBuilder(configService.Name, ServiceSource.Configuration);
service = external;
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/AzureFunctionServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Microsoft.Tye
{
public class AzureFunctionServiceBuilder : ServiceBuilder
{
public AzureFunctionServiceBuilder(string name, string path)
: base(name)
public AzureFunctionServiceBuilder(string name, string path, ServiceSource source)
: base(name, source)
{
FunctionPath = path;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/ContainerServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Tye
{
public sealed class ContainerServiceBuilder : ServiceBuilder
{
public ContainerServiceBuilder(string name, string image)
: base(name)
public ContainerServiceBuilder(string name, string image, ServiceSource source)
: base(name, source)
{
Image = image;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/DockerFileServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Tye
{
public class DockerFileServiceBuilder : ProjectServiceBuilder
{
public DockerFileServiceBuilder(string name, string image)
: base(name)
public DockerFileServiceBuilder(string name, string image, ServiceSource source)
: base(name, source)
{
Image = image;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/DotnetProjectServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Microsoft.Tye
{
public class DotnetProjectServiceBuilder : ProjectServiceBuilder
{
public DotnetProjectServiceBuilder(string name, FileInfo projectFile)
: base(name)
public DotnetProjectServiceBuilder(string name, FileInfo projectFile, ServiceSource source)
: base(name, source)
{
ProjectFile = projectFile;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/ExecutableServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Tye
{
public sealed class ExecutableServiceBuilder : LaunchedServiceBuilder
{
public ExecutableServiceBuilder(string name, string executable)
: base(name)
public ExecutableServiceBuilder(string name, string executable, ServiceSource source)
: base(name, source)
{
Executable = executable;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/ExternalServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Microsoft.Tye
{
public sealed class ExternalServiceBuilder : ServiceBuilder
{
public ExternalServiceBuilder(string name)
: base(name)
public ExternalServiceBuilder(string name, ServiceSource source)
: base(name, source)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/LaunchedServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Tye
{
public abstract class LaunchedServiceBuilder : ServiceBuilder
{
public LaunchedServiceBuilder(string name)
: base(name)
public LaunchedServiceBuilder(string name, ServiceSource source)
: base(name, source)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Core/ProjectServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Tye
{
public class ProjectServiceBuilder : LaunchedServiceBuilder
{
public ProjectServiceBuilder(string name)
: base(name)
public ProjectServiceBuilder(string name, ServiceSource source)
: base(name, source)
{
}
public bool IsAspNet { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion src/Microsoft.Tye.Core/ServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ namespace Microsoft.Tye
{
public abstract class ServiceBuilder
{
public ServiceBuilder(string name)
public ServiceBuilder(string name, ServiceSource source)
{
Name = name;
Source = source;
}

public string Name { get; }
Expand All @@ -17,5 +18,7 @@ public ServiceBuilder(string name)
public List<ServiceOutput> Outputs { get; } = new List<ServiceOutput>();

public HashSet<string> Dependencies { get; } = new HashSet<string>();

public ServiceSource Source { get; }
}
}
14 changes: 14 additions & 0 deletions src/Microsoft.Tye.Core/ServiceSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.Tye
{
public enum ServiceSource
{
Unknown = 0,
Configuration,
Extension,
Host
}
}
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Extensions/Dapr/DaprExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati
}

context.Output.WriteDebugLine("Injecting Dapr placement service...");
var daprPlacement = new ContainerServiceBuilder("placement", daprPlacementImage)
var daprPlacement = new ContainerServiceBuilder("placement", daprPlacementImage, ServiceSource.Extension)
{
Args = "./placement",
Bindings = {
Expand Down Expand Up @@ -104,7 +104,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati

var daprExecutablePath = GetDaprExecutablePath();

var proxy = new ExecutableServiceBuilder($"{project.Name}-dapr", daprExecutablePath)
var proxy = new ExecutableServiceBuilder($"{project.Name}-dapr", daprExecutablePath, ServiceSource.Extension)
{
WorkingDirectory = context.Application.Source.DirectoryName,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati
// easy to set up.
//
// See: https://elk-docker.readthedocs.io/
var elastic = new ContainerServiceBuilder("elastic", "sebp/elk")
var elastic = new ContainerServiceBuilder("elastic", "sebp/elk", ServiceSource.Extension)
{
Bindings =
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati
{
context.Output.WriteDebugLine("Injecting seq service...");

var seq = new ContainerServiceBuilder("seq", "datalust/seq")
var seq = new ContainerServiceBuilder("seq", "datalust/seq", ServiceSource.Extension)
{
EnvironmentVariables =
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Extensions/Zipkin/ZipkinExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati
else
{
context.Output.WriteDebugLine("Injecting zipkin service...");
var service = new ContainerServiceBuilder("zipkin", "openzipkin/zipkin")
var service = new ContainerServiceBuilder("zipkin", "openzipkin/zipkin", ServiceSource.Extension)
{
Bindings =
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Hosting/DockerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task StartAsync(Application application)
b.ReplicaPorts.Add(b.Port.Value);
proxyDescription.Bindings.Add(b);
}
var proxyContainerService = new Service(proxyDescription);
var proxyContainerService = new Service(proxyDescription, ServiceSource.Host);
containers.Add(proxyContainerService);
proxies.Add(proxyContainerService);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.Tye.Hosting/Model/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Tye.Hosting.Model
{
public class Service
{
public Service(ServiceDescription description)
public Service(ServiceDescription description, ServiceSource source)
{
Description = description;

Expand All @@ -29,12 +29,16 @@ public Service(ServiceDescription description)
{
entry.Replica.State = entry.State;
});

ServiceSource = source;
}

public ServiceDescription Description { get; }

public int Restarts { get; set; }

public ServiceSource ServiceSource { get; }

public ServiceType ServiceType
{
get
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Tye.Hosting/Model/V1/V1Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.Tye.Hosting.Model.V1
public class V1Service
{
public V1ServiceDescription? Description { get; set; }
public ServiceSource ServiceSource { get; set; }
public ServiceType ServiceType { get; set; }
public int Restarts { get; set; }
public V1ServiceStatus? Status { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Tye.Hosting/TyeDashboardApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private static V1Service CreateServiceJson(Service service)

var serviceJson = new V1Service()
{
ServiceSource = service.ServiceSource,
ServiceType = service.ServiceType,
Status = v1Status,
Description = v1ServiceDescription,
Expand Down
4 changes: 2 additions & 2 deletions src/tye/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static Application ToHostingApplication(this ApplicationBuilder applicati
});
}

services.Add(service.Name, new Service(description));
services.Add(service.Name, new Service(description, service.Source));
}

// Ingress get turned into services for hosting
Expand Down Expand Up @@ -210,7 +210,7 @@ public static Application ToHostingApplication(this ApplicationBuilder applicati
});
}

services.Add(ingress.Name, new Service(description));
services.Add(ingress.Name, new Service(description, ServiceSource.Host));
}

return new Application(application.Name, application.Source, services, application.ContainerEngine) { Network = application.Network };
Expand Down
4 changes: 2 additions & 2 deletions test/E2ETest/TyeRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public async Task FrontendProjectBackendDocker()
application.Services.Remove(project);

var outputFileName = project.AssemblyName + ".dll";
var container = new ContainerServiceBuilder(project.Name, $"mcr.microsoft.com/dotnet/core/aspnet:{project.TargetFrameworkVersion}")
var container = new ContainerServiceBuilder(project.Name, $"mcr.microsoft.com/dotnet/core/aspnet:{project.TargetFrameworkVersion}", ServiceSource.Configuration)
{
IsAspNet = true
};
Expand Down Expand Up @@ -296,7 +296,7 @@ public async Task FrontendDockerBackendProject()
application.Services.Remove(project);

var outputFileName = project.AssemblyName + ".dll";
var container = new ContainerServiceBuilder(project.Name, $"mcr.microsoft.com/dotnet/core/aspnet:{project.TargetFrameworkVersion}")
var container = new ContainerServiceBuilder(project.Name, $"mcr.microsoft.com/dotnet/core/aspnet:{project.TargetFrameworkVersion}", ServiceSource.Configuration)
{
IsAspNet = true
};
Expand Down

0 comments on commit 4588079

Please sign in to comment.