示例#1
0
        public Task VerifyListenMode(MonitorImageData imageData, SampleImageData sampleData)
        {
            return(VerifyScenarioAsync(
                       monitorImageData: imageData,
                       sampleImageData: sampleData,
                       shareTmpVolume: false,
                       listenDiagPortVolume: true,
                       noAuthentication: true,
                       async(monitorName, sampleName) =>
            {
                if (!Config.IsHttpVerificationDisabled)
                {
                    using HttpResponseMessage responseMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  monitorName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultArtifactsPort,
                                  UrlPath_Processes);

                    JsonElement rootElement = GetContentAsJsonElement(responseMessage);

                    // Verify returns an array with one element (the sample container process)
                    Assert.Equal(JsonValueKind.Array, rootElement.ValueKind);
                    Assert.Equal(1, rootElement.GetArrayLength());
                }
            }));
        }
示例#2
0
        public Task VerifyMonitorNoHttpsNoAuth(MonitorImageData imageData)
        {
            return(VerifyMonitorAsync(
                       imageData,
                       noAuthentication: true,
                       async containerName =>
            {
                if (!Config.IsHttpVerificationDisabled)
                {
                    // Verify metrics endpoint is accessible and produces zero processes
                    using HttpResponseMessage processesMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  containerName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultArtifactsPort,
                                  UrlPath_Processes);

                    JsonElement rootElement = GetContentAsJsonElement(processesMessage);

                    // Verify returns an empty array (should not detect any processes)
                    Assert.Equal(JsonValueKind.Array, rootElement.ValueKind);
                    Assert.Equal(0, rootElement.GetArrayLength());
                }
            },
                       builder =>
            {
                // Reset and expose the artifacts port over http (not secure)
                builder.MonitorUrl(DefaultArtifactsPort);
            }));
        }
示例#3
0
 public Task VerifyMonitorNoHttps(MonitorImageData imageData)
 {
     return(VerifyMonitorAsync(
                imageData,
                noAuthentication: false,
                async containerName =>
     {
         if (!Config.IsHttpVerificationDisabled)
         {
             // Verify processes returns 401 (Unauthorized) since authentication was not provided.
             using HttpResponseMessage processesMessage =
                       await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                           containerName,
                           DockerHelper,
                           OutputHelper,
                           DefaultArtifactsPort,
                           UrlPath_Processes,
                           m => VerifyStatusCode(m, HttpStatusCode.Unauthorized));
         }
     },
                builder =>
     {
         // Reset and expose the artifacts port over http (not secure)
         builder.MonitorUrl(DefaultArtifactsPort);
     }));
 }
示例#4
0
        /// <summary>
        /// Runs a single instance of the dotnet-monitor image.
        /// </summary>
        /// <param name="imageData">The image data of the dotnet-monitor image.</param>
        /// <param name="noAuthentication">Set to true to disable dotnet-monitor authenication.</param>
        /// <param name="verifyContainerAsync">Callback to test some aspect of the container.</param>
        /// <param name="runArgsCallback">Allows for modifying the "docker run" args of the container.</param>
        private async Task VerifyMonitorAsync(
            MonitorImageData imageData,
            bool noAuthentication,
            Func <string, Task> verifyContainerAsync      = null,
            Action <DockerRunArgsBuilder> runArgsCallback = null)
        {
            GetNames(imageData, out string monitorImageName, out string monitorContainerName);
            try
            {
                DockerRunArgsBuilder runArgsBuilder = DockerRunArgsBuilder.Create()
                                                      .ExposePort(DefaultMetricsPort);

                if (null != runArgsCallback)
                {
                    runArgsCallback(runArgsBuilder);
                }

                DockerHelper.Run(
                    image: monitorImageName,
                    name: monitorContainerName,
                    command: GetMonitorAdditionalArgs(noAuthentication),
                    detach: true,
                    optionalRunArgs: runArgsBuilder.Build());

                if (!Config.IsHttpVerificationDisabled)
                {
                    // Verify metrics endpoint is accessible
                    using HttpResponseMessage metricsMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  monitorContainerName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultMetricsPort,
                                  UrlPath_Metrics);

                    string metricsContent = await metricsMessage.Content.ReadAsStringAsync();

                    // Metrics should not return any content if
                    // no processes are detected.
                    Assert.Equal(string.Empty, metricsContent);
                }

                if (null != verifyContainerAsync)
                {
                    await verifyContainerAsync(monitorContainerName);
                }
            }
            finally
            {
                DockerHelper.DeleteContainer(monitorContainerName);
            }
        }
示例#5
0
        public void VerifyEnvironmentVariables(MonitorImageData imageData)
        {
            List <EnvironmentVariableInfo> variables = new List <EnvironmentVariableInfo>();

            variables.AddRange(ProductImageTests.GetCommonEnvironmentVariables());

            // ASPNETCORE_URLS has been unset to allow the default URL binding to occur.
            variables.Add(new EnvironmentVariableInfo("ASPNETCORE_URLS", string.Empty));
            // Diagnostics should be disabled
            variables.Add(new EnvironmentVariableInfo("COMPlus_EnableDiagnostics", "0"));

            EnvironmentVariableInfo.Validate(
                variables,
                imageData.GetImage(DockerHelper),
                imageData,
                DockerHelper);
        }
        public void VerifyEnvironmentVariables(MonitorImageData imageData)
        {
            List <EnvironmentVariableInfo> variables = new List <EnvironmentVariableInfo>();

            variables.AddRange(ProductImageTests.GetCommonEnvironmentVariables());

            // ASPNETCORE_URLS has been unset to allow the default URL binding to occur.
            variables.Add(new EnvironmentVariableInfo("ASPNETCORE_URLS", string.Empty));
            // Diagnostics should be disabled
            variables.Add(new EnvironmentVariableInfo("COMPlus_EnableDiagnostics", "0"));
            // DefaultProcess filter should select a process with a process ID of 1
            variables.Add(new EnvironmentVariableInfo("DefaultProcess__Filters__0__Key", "ProcessId"));
            variables.Add(new EnvironmentVariableInfo("DefaultProcess__Filters__0__Value", "1"));
            // Console logger format should be JSON and output UTC timestamps without timezone information
            variables.Add(new EnvironmentVariableInfo("Logging__Console__FormatterName", "json"));
            variables.Add(new EnvironmentVariableInfo("Logging__Console__FormatterOptions__TimestampFormat", "yyyy-MM-ddTHH:mm:ss.fffffffZ"));
            variables.Add(new EnvironmentVariableInfo("Logging__Console__FormatterOptions__UseUtcTimestamp", "true"));

            EnvironmentVariableInfo.Validate(
                variables,
                imageData.GetImage(DockerHelper),
                imageData,
                DockerHelper);
        }
示例#7
0
 private void GetNames(MonitorImageData imageData, out string imageName, out string containerName)
 {
     imageName     = imageData.GetImage(DockerHelper);
     containerName = imageData.GetIdentifier("monitortest");
 }
示例#8
0
 private static SampleImageData GetSampleImageData(MonitorImageData imageData)
 {
     return(TestData.GetSampleImageData()
            .First(d => d.IsPublished = true && d.Arch == imageData.Arch));
 }
示例#9
0
        /// <summary>
        /// Runs a single instance of each of the dotnet-monitor and samples images.
        /// </summary>
        /// <param name="monitorImageData">The image data of the dotnet-monitor image.</param>
        /// <param name="shareTmpVolume">Set to true to mount the /tmp directory in both containers.</param>
        /// <param name="listenDiagPortVolume">
        /// Set to true to have the monitor container listen with a diagnostic port listener
        /// for diagnostic connections from the samples container.
        /// </param>
        /// <param name="noAuthentication">Set to true to disable dotnet-monitor authenication.</param>
        /// <param name="verifyContainerAsync">Callback to test some aspect of the containers.</param>
        /// <param name="monitorRunArgsCallback">Allows for modifying the "docker run" args of the dotnet-monitor container.</param>
        /// <param name="sampleRunArgsCallback">Allows for modifying the "docker run" args of the samples container.</param>
        private async Task VerifyScenarioAsync(
            MonitorImageData monitorImageData,
            SampleImageData sampleImageData,
            bool shareTmpVolume,
            bool listenDiagPortVolume,
            bool noAuthentication,
            Func <string, string, Task> verifyContainerAsync,
            Action <DockerRunArgsBuilder> monitorRunArgsCallback = null,
            Action <DockerRunArgsBuilder> sampleRunArgsCallback  = null)
        {
            GetNames(monitorImageData, out string monitorImageName, out string monitorContainerName);
            GetNames(sampleImageData, out string sampleImageName, out string sampleContainerName);

            DockerRunArgsBuilder monitorArgsBuilder = DockerRunArgsBuilder.Create()
                                                      .MonitorUrl(DefaultArtifactsPort);

            DockerRunArgsBuilder sampleArgsBuilder = DockerRunArgsBuilder.Create()
                                                     .ExposePort(DefaultHttpPort);

            string diagPortVolumeName = null;
            string tmpVolumeName      = null;

            try
            {
                // Create a volume for the two containers to share the /tmp directory.
                if (shareTmpVolume)
                {
                    tmpVolumeName = DockerHelper.CreateVolume(UniqueName("tmpvol"));

                    monitorArgsBuilder.VolumeMount(tmpVolumeName, Directory_Tmp);

                    sampleArgsBuilder.VolumeMount(tmpVolumeName, Directory_Tmp);
                }

                // Create a volume so that the dotnet-monitor container can provide a
                // diagnostic listening port to the samples container so that the samples
                // process can connect to the dotnet-monitor process.
                if (listenDiagPortVolume)
                {
                    diagPortVolumeName = DockerHelper.CreateVolume(UniqueName("diagportvol"));

                    monitorArgsBuilder.VolumeMount(diagPortVolumeName, Directory_Diag);
                    monitorArgsBuilder.MonitorListen(File_DiagPort);

                    sampleArgsBuilder.VolumeMount(diagPortVolumeName, Directory_Diag);
                    sampleArgsBuilder.RuntimeSuspend(File_DiagPort);
                }

                // Allow modification of the "docker run" args of the monitor container
                if (null != monitorRunArgsCallback)
                {
                    monitorRunArgsCallback(monitorArgsBuilder);
                }

                // Allow modification of the "docker run" args of the samples container
                if (null != sampleRunArgsCallback)
                {
                    sampleRunArgsCallback(sampleArgsBuilder);
                }

                // Run the sample container
                DockerHelper.Run(
                    image: sampleImageName,
                    name: sampleContainerName,
                    detach: true,
                    optionalRunArgs: sampleArgsBuilder.Build());

                // Run the dotnet-monitor container
                DockerHelper.Run(
                    image: monitorImageName,
                    name: monitorContainerName,
                    command: GetMonitorAdditionalArgs(noAuthentication),
                    detach: true,
                    optionalRunArgs: monitorArgsBuilder.Build());

                await verifyContainerAsync(
                    monitorContainerName,
                    sampleContainerName);
            }
            finally
            {
                DockerHelper.DeleteContainer(monitorContainerName);

                DockerHelper.DeleteContainer(sampleContainerName);

                if (!string.IsNullOrEmpty(diagPortVolumeName))
                {
                    DockerHelper.DeleteVolume(diagPortVolumeName);
                }

                if (!string.IsNullOrEmpty(tmpVolumeName))
                {
                    DockerHelper.DeleteVolume(tmpVolumeName);
                }
            }
        }
示例#10
0
 public Task VerifyMonitorDefault(MonitorImageData imageData)
 {
     return(VerifyMonitorAsync(imageData, noAuthentication: false));
 }