Beispiel #1
0
        public void CanRoundTripIntegrationIds()
        {
            using var scope = new AssertionScope();
            var values = IntegrationRegistry.Ids.Values;

            values.Should().HaveCountGreaterThan(0);

            foreach (var i in IntegrationRegistry.Ids.Values)
            {
                var integrationId = (IntegrationId)i;
                var name          = IntegrationRegistry.GetName(integrationId);
                IntegrationRegistry.TryGetIntegrationId(name, out var parsedId1).Should().BeTrue();
                IntegrationRegistry.TryGetIntegrationId(name.ToUpperInvariant(), out var parsedId2).Should().BeTrue();
                IntegrationRegistry.TryGetIntegrationId(name.ToLowerInvariant(), out var parsedId3).Should().BeTrue();

                parsedId1.Should().Be(integrationId);
                parsedId2.Should().Be(integrationId);
                parsedId3.Should().Be(integrationId);
            }
        }
        public static ImmutableDirectLogSubmissionSettings Create(
            string?host,
            string?source,
            string?intakeUrl,
            string?apiKey,
            DirectSubmissionLogLevel minimumLevel,
            IDictionary <string, string> globalTags,
            ICollection <string> enabledLogShippingIntegrations,
            BatchingSinkOptions batchingOptions)
        {
            if (enabledLogShippingIntegrations.Count == 0)
            {
                // not trying to enable log submission, so don't log any errors and create a _null_ implementation
                return(CreateNullSettings());
            }

            var isEnabled        = true;
            var validationErrors = new List <string>();

            if (string.IsNullOrWhiteSpace(host))
            {
                isEnabled = false;
                validationErrors.Add($"Missing required setting '{ConfigurationKeys.DirectLogSubmission.Host}'.");
            }

            if (string.IsNullOrWhiteSpace(source))
            {
                isEnabled = false;
                validationErrors.Add($"Missing required setting '{ConfigurationKeys.DirectLogSubmission.Source}'.");
            }

            if (!Uri.TryCreate(intakeUrl, UriKind.Absolute, out var intakeUri))
            {
                isEnabled = false;
                validationErrors.Add($"The intake url '{intakeUrl}' was not a valid URL.");
            }

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                isEnabled = false;
                validationErrors.Add($"Missing required settings '{ConfigurationKeys.ApiKey}'.");
            }

            var stringifiedTags         = StringifyGlobalTags(globalTags);
            var enabledIntegrations     = new bool[IntegrationRegistry.Ids.Count];
            var enabledIntegrationNames = new List <string>(SupportedIntegrations.Length);

            foreach (var integrationName in enabledLogShippingIntegrations)
            {
                if (!IntegrationRegistry.TryGetIntegrationId(integrationName, out var integrationId))
                {
                    validationErrors.Add(
                        "Unknown integration: " + integrationName +
                        ". Use a valid logs integration name: " +
                        string.Join(", ", SupportedIntegrations.Select(x => IntegrationRegistry.GetName(x))));
                    continue;
                }

                if (!SupportedIntegrations.Contains(integrationId))
                {
                    validationErrors.Add(
                        "Integration: " + integrationName + " is not a supported direct log submission integration. " +
                        "Use one of " + string.Join(", ", SupportedIntegrations.Select(x => IntegrationRegistry.GetName(x))));
                    continue;
                }

                if (!enabledIntegrations[(int)integrationId])
                {
                    enabledIntegrationNames.Add(IntegrationRegistry.GetName(integrationId));
                    enabledIntegrations[(int)integrationId] = true;
                }
            }

            return(new ImmutableDirectLogSubmissionSettings(
                       host: host ?? string.Empty,
                       source: source ?? string.Empty,
                       globalTags: stringifiedTags,
                       intakeUrl: intakeUri !,
                       apiKey: apiKey ?? string.Empty,
                       isEnabled: isEnabled,
                       minimumLevel: minimumLevel,
                       enabledIntegrations: enabledIntegrations,
                       validationErrors,
                       enabledIntegrationNames,
                       batchingOptions));
        }
Beispiel #3
0
 public void TryGetIntegrationId_ReturnsFalseForUnknownIntegration()
 {
     IntegrationRegistry.TryGetIntegrationId("blobby", out _).Should().BeFalse();
 }