Esempio n. 1
0
 public Endpoint(ITimeCoordinator timeCoordinator, EndpointIdentity identity, EndpointMetadata metadata, string password = null)
 {
     _timeCoordinator = timeCoordinator;
     Identity = identity;
     Metadata = metadata;
     Password = password;
     UpdateLastModifiedTime();
 }
        public void UpdateEndpoints(EndpointIdentity[] identities)
        {
            foreach (var endpoint in identities)
                TryRegister(endpoint);

            foreach (var removed in Endpoints.Where(e => identities.All(i => i.Id != e.Identity.Id)))
                TryUnregister(removed.Identity);
        }
        public MonitorableEndpoint(EndpointIdentity identity, IHealthMonitor monitor)
        {
            if (identity == null)
                throw new ArgumentNullException(nameof(identity));
            if (monitor == null)
                throw new ArgumentNullException(nameof(monitor));

            Identity = identity;
            Monitor = monitor;
        }
        public bool TryUnregister(EndpointIdentity identity)
        {
            MonitorableEndpoint removedEndpoint;
            if (!_endpoints.TryRemove(identity.Id, out removedEndpoint))
                return false;

            removedEndpoint.Dispose();
            Logger.Info($"Stopped monitoring of: {removedEndpoint}");
            return true;
        }
        public void HandleMetricsForwarding(EndpointIdentity identity, EndpointMetadata metadata, EndpointHealth health)
        {
            var ed = new EndpointDetails(identity.Id, metadata.Group, metadata.Name, identity.Address, identity.MonitorType);
            var em = new EndpointMetrics(health.CheckTimeUtc, health.ResponseTime.Milliseconds, health.Status.ToString());

            foreach (var f in _forwarders)
            {
                Logger.InfoFormat("Forwarding metrics using {0} forwarder, for endpoint id {1}", f.Key, identity.Id);

                f.Value.ForwardEndpointMetrics(ed, em);
            }
        }
        public void TryRegister_should_register_new_endpoint_and_emit_NewEndpointAdded_event()
        {
            MockMonitor("monitor");

            MonitorableEndpoint capturedEndpoint = null;
            _registry.NewEndpointAdded += e => { capturedEndpoint = e; };

            var endpointIdentity = new EndpointIdentity(Guid.NewGuid(), "monitor", "address");
            var endpoint = _registry.TryRegister(endpointIdentity);

            Assert.NotNull(endpoint);
            Assert.Same(endpoint, capturedEndpoint);
            Assert.Equal("monitor", endpoint.Identity.MonitorType);
            Assert.Equal("address", endpoint.Identity.Address);
            Assert.Equal(endpointIdentity.Id, endpoint.Identity.Id);
        }
        public MonitorableEndpoint TryRegister(EndpointIdentity identity)
        {
            var monitor = _healthMonitorRegistry.FindByName(identity.MonitorType);
            if (monitor == null)
                return null;

            var monitorableEndpoint = new MonitorableEndpoint(identity, monitor);

            var current = _endpoints.GetOrAdd(identity.Id, monitorableEndpoint);

            if (ReferenceEquals(current, monitorableEndpoint))
            {
                Logger.Info($"Starting monitoring of: {monitorableEndpoint}");
                NewEndpointAdded?.Invoke(monitorableEndpoint);
            }
            return current;
        }
        public void UpdateEndpoints_should_register_new_endpoints_dispose_not_specified_ones_and_ignore_ones_with_unrecognized_monitor_type()
        {
            MockMonitor("monitor");
            var e1 = _registry.TryRegister(new EndpointIdentity(Guid.NewGuid(), "monitor", "address"));
            var e2 = _registry.TryRegister(new EndpointIdentity(Guid.NewGuid(), "monitor", "address2"));
            var e3 = _registry.TryRegister(new EndpointIdentity(Guid.NewGuid(), "monitor", "address3"));
            var i4 = new EndpointIdentity(Guid.NewGuid(), "monitor", "address4");
            var i5 = new EndpointIdentity(Guid.NewGuid(), "monitor", "address4");
            var i6 = new EndpointIdentity(Guid.NewGuid(), "unknownMonitor", "address4");

            List<MonitorableEndpoint> captured = new List<MonitorableEndpoint>();
            _registry.NewEndpointAdded += e => captured.Add(e);

            _registry.UpdateEndpoints(e1.Identity, e2.Identity, i4, i5, i6);

            Assert.Equal(2, captured.Count);
            Assert.Contains(i4, captured.Select(c => c.Identity));
            Assert.Contains(i5, captured.Select(c => c.Identity));

            Assert.False(e1.IsDisposed, "e1.IsDisposed");
            Assert.False(e2.IsDisposed, "e2.IsDisposed");
            Assert.True(e3.IsDisposed, "e3.IsDisposed");
        }
 public void RecordEndpointStatistics(EndpointIdentity identity, EndpointMetadata metadata, EndpointHealth stats)
 {
     _statsQueue.Enqueue(Tuple.Create(identity, metadata, stats));
 }