From 6dfde68572eb34be119ce9e2ce0fb0636ac341d0 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 1 May 2020 17:52:41 -0700 Subject: [PATCH] Add basic zipkin extension This starts the zipkin container, but `--dtrace zipkin=...` is still needed for now. --- .../WellKnownExtensions.cs | 2 + .../Zipkin/ZipkinExtension.cs | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Microsoft.Tye.Extensions/Zipkin/ZipkinExtension.cs diff --git a/src/Microsoft.Tye.Extensions/WellKnownExtensions.cs b/src/Microsoft.Tye.Extensions/WellKnownExtensions.cs index 1498b105..40198212 100644 --- a/src/Microsoft.Tye.Extensions/WellKnownExtensions.cs +++ b/src/Microsoft.Tye.Extensions/WellKnownExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.Tye.Extensions.Dapr; +using Microsoft.Tye.Extensions.Zipkin; namespace Microsoft.Tye.Extensions { @@ -13,6 +14,7 @@ namespace Microsoft.Tye.Extensions public static IReadOnlyDictionary Extensions = new Dictionary(StringComparer.InvariantCultureIgnoreCase) { { "dapr", new DaprExtension() }, + { "zipkin", new ZipkinExtension() }, }; } } diff --git a/src/Microsoft.Tye.Extensions/Zipkin/ZipkinExtension.cs b/src/Microsoft.Tye.Extensions/Zipkin/ZipkinExtension.cs new file mode 100644 index 00000000..c344a3ad --- /dev/null +++ b/src/Microsoft.Tye.Extensions/Zipkin/ZipkinExtension.cs @@ -0,0 +1,45 @@ +// 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. + +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.Tye.Extensions.Zipkin +{ + internal sealed class ZipkinExtension : Extension + { + public override string Name => "zipkin"; + + public override Task ProcessAsync(ExtensionContext context, ExtensionConfiguration config) + { + if (context.Application.Services.Any(s => s.Name == "zipkin")) + { + context.Output.WriteDebugLine("Zipkin service already configured. Skipping..."); + return Task.CompletedTask; + } + + if (context.Operation == ExtensionContext.OperationKind.LocalRun) + { + var service = new ContainerServiceBuilder("zipkin", "openzipkin/zipkin") + { + Bindings = + { + new BindingBuilder() + { + Port = 9411, + ContainerPort = 9411, + Protocol = "http", + }, + }, + }; + context.Application.Services.Add(service); + } + + return Task.CompletedTask; + } + } +}