|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.Extensions.Logging; |
| 5 | +using NuGet.Services.Incidents; |
| 6 | +using NuGet.Services.Status; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Text.RegularExpressions; |
| 9 | + |
| 10 | +namespace StatusAggregator.Parse |
| 11 | +{ |
| 12 | + public class TrafficManagerEndpointStatusIncidentParser : EnvironmentPrefixIncidentParser |
| 13 | + { |
| 14 | + private const string DomainGroupName = "Domain"; |
| 15 | + private const string TargetGroupName = "Target"; |
| 16 | + private static string SubtitleRegEx = $"Traffic Manager for (?<{DomainGroupName}>.*) is reporting (?<{TargetGroupName}>.*) as not Online!"; |
| 17 | + |
| 18 | + private readonly ILogger<TrafficManagerEndpointStatusIncidentParser> _logger; |
| 19 | + |
| 20 | + public TrafficManagerEndpointStatusIncidentParser( |
| 21 | + IEnumerable<IIncidentParsingFilter> filters, |
| 22 | + ILogger<TrafficManagerEndpointStatusIncidentParser> logger) |
| 23 | + : base(SubtitleRegEx, filters, logger) |
| 24 | + { |
| 25 | + _logger = logger; |
| 26 | + } |
| 27 | + |
| 28 | + protected override bool TryParseAffectedComponentPath(Incident incident, GroupCollection groups, out string affectedComponentPath) |
| 29 | + { |
| 30 | + affectedComponentPath = null; |
| 31 | + |
| 32 | + var domain = groups[DomainGroupName].Value; |
| 33 | + var target = groups[TargetGroupName].Value; |
| 34 | + var environment = groups[EnvironmentFilter.EnvironmentGroupName].Value; |
| 35 | + _logger.LogInformation("Domain is {Domain}, target is {Target}, environment is {Environment}.", domain, target, environment); |
| 36 | + |
| 37 | + if (EnvironmentToDomainToTargetToPath.TryGetValue(environment, out var domainToTargetToPath) && |
| 38 | + domainToTargetToPath.TryGetValue(domain, out var targetToPath) && |
| 39 | + targetToPath.TryGetValue(target, out var path)) |
| 40 | + { |
| 41 | + affectedComponentPath = path; |
| 42 | + } |
| 43 | + |
| 44 | + return affectedComponentPath != null; |
| 45 | + } |
| 46 | + |
| 47 | + protected override bool TryParseAffectedComponentStatus(Incident incident, GroupCollection groups, out ComponentStatus affectedComponentStatus) |
| 48 | + { |
| 49 | + affectedComponentStatus = ComponentStatus.Down; |
| 50 | + return true; |
| 51 | + } |
| 52 | + |
| 53 | + private static readonly string GalleryUsncPath = |
| 54 | + ComponentUtility.GetPath( |
| 55 | + NuGetServiceComponentFactory.RootName, |
| 56 | + NuGetServiceComponentFactory.GalleryName, |
| 57 | + NuGetServiceComponentFactory.UsncInstanceName); |
| 58 | + |
| 59 | + private static readonly string GalleryUsscPath = |
| 60 | + ComponentUtility.GetPath( |
| 61 | + NuGetServiceComponentFactory.RootName, |
| 62 | + NuGetServiceComponentFactory.GalleryName, |
| 63 | + NuGetServiceComponentFactory.UsscInstanceName); |
| 64 | + |
| 65 | + private static readonly string RestoreV3GlobalPath = |
| 66 | + ComponentUtility.GetPath( |
| 67 | + NuGetServiceComponentFactory.RootName, |
| 68 | + NuGetServiceComponentFactory.RestoreName, |
| 69 | + NuGetServiceComponentFactory.V3ProtocolName, |
| 70 | + NuGetServiceComponentFactory.GlobalRegionName); |
| 71 | + |
| 72 | + private static readonly string RestoreV3ChinaPath = |
| 73 | + ComponentUtility.GetPath( |
| 74 | + NuGetServiceComponentFactory.RootName, |
| 75 | + NuGetServiceComponentFactory.RestoreName, |
| 76 | + NuGetServiceComponentFactory.V3ProtocolName, |
| 77 | + NuGetServiceComponentFactory.ChinaRegionName); |
| 78 | + |
| 79 | + private static readonly IDictionary<string, IDictionary<string, string>> DevDomainToTargetToPath = |
| 80 | + new Dictionary<string, IDictionary<string, string>> |
| 81 | + { |
| 82 | + { |
| 83 | + "devnugettest.trafficmanager.net", |
| 84 | + new Dictionary<string, string> |
| 85 | + { |
| 86 | + { |
| 87 | + "nuget-dev-use2-gallery.cloudapp.net", |
| 88 | + GalleryUsncPath |
| 89 | + }, |
| 90 | + |
| 91 | + { |
| 92 | + "nuget-dev-ussc-gallery.cloudapp.net", |
| 93 | + GalleryUsncPath |
| 94 | + } |
| 95 | + } |
| 96 | + }, |
| 97 | + |
| 98 | + { |
| 99 | + "nugetapidev.trafficmanager.net", |
| 100 | + new Dictionary<string, string> |
| 101 | + { |
| 102 | + { |
| 103 | + "az635243.vo.msecnd.net", |
| 104 | + RestoreV3GlobalPath |
| 105 | + }, |
| 106 | + { |
| 107 | + "nugetdevcnredirect.trafficmanager.net", |
| 108 | + RestoreV3ChinaPath |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + }; |
| 113 | + |
| 114 | + private static readonly IDictionary<string, IDictionary<string, string>> IntDomainToTargetToPath = |
| 115 | + new Dictionary<string, IDictionary<string, string>> |
| 116 | + { |
| 117 | + { |
| 118 | + "nuget-int-test-failover.trafficmanager.net", |
| 119 | + new Dictionary<string, string> |
| 120 | + { |
| 121 | + { |
| 122 | + "nuget-int-0-v2gallery.cloudapp.net", |
| 123 | + GalleryUsncPath |
| 124 | + }, |
| 125 | + |
| 126 | + { |
| 127 | + "nuget-int-ussc-gallery.cloudapp.net", |
| 128 | + GalleryUsncPath |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + }; |
| 133 | + |
| 134 | + private static readonly IDictionary<string, IDictionary<string, string>> ProdDomainToTargetToPath = |
| 135 | + new Dictionary<string, IDictionary<string, string>> |
| 136 | + { |
| 137 | + { |
| 138 | + "nuget-prod-v2gallery.trafficmanager.net", |
| 139 | + new Dictionary<string, string> |
| 140 | + { |
| 141 | + { |
| 142 | + "nuget-prod-0-v2gallery.cloudapp.net", |
| 143 | + GalleryUsncPath |
| 144 | + }, |
| 145 | + |
| 146 | + { |
| 147 | + "nuget-prod-ussc-gallery.cloudapp.net", |
| 148 | + GalleryUsncPath |
| 149 | + } |
| 150 | + } |
| 151 | + }, |
| 152 | + |
| 153 | + { |
| 154 | + "nugetapiprod.trafficmanager.net", |
| 155 | + new Dictionary<string, string> |
| 156 | + { |
| 157 | + { |
| 158 | + "az320820.vo.msecnd.net", |
| 159 | + RestoreV3GlobalPath |
| 160 | + }, |
| 161 | + { |
| 162 | + "nugetprodcnredirect.trafficmanager.net", |
| 163 | + RestoreV3ChinaPath |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + }; |
| 168 | + |
| 169 | + private static readonly IDictionary<string, IDictionary<string, IDictionary<string, string>>> EnvironmentToDomainToTargetToPath = |
| 170 | + new Dictionary<string, IDictionary<string, IDictionary<string, string>>> |
| 171 | + { |
| 172 | + { "dev", DevDomainToTargetToPath }, |
| 173 | + { "test", DevDomainToTargetToPath }, |
| 174 | + { "int", IntDomainToTargetToPath }, |
| 175 | + { "prod", ProdDomainToTargetToPath } |
| 176 | + }; |
| 177 | + } |
| 178 | +} |
0 commit comments