Exemple #1
0
    def tcp(cls, service, params):
        """
        Consul TCP Check

        This feature is only available when using Consul 0.6 or newer.
        Containers specifying these extra metadata in labels or environment will be used to register
        an TCP health check with the service.

        SERVICE_443_CHECK_TCP=true
        SERVICE_443_CHECK_INTERVAL=15s
        SERVICE_443_CHECK_TIMEOUT=3s		# optional, Consul default used otherwise
        """
        # https://github.com/cablehead/python-consul/blob/53eb41c4760b983aec878ef73e72c11e0af501bb/consul/base.py#L85
        # https://github.com/gliderlabs/registrator/blob/master/docs/user/backends.md#consul-tcp-check
        tcp = cls._bool_value(params, 'tcp')
        if tcp:
            # Attempt to establish a tcp connection to the specified *host* and
            # *port* at a specified *interval* with optional *timeout* and optional
            # *deregister* after which a failing service will be automatically
            # deregistered.
            host = service.ip
            port = service.port
            interval, deregister = cls._common_values(params)
            timeout = cls._value(params, 'timeout')
            ret = Check.tcp(host,
                            port,
                            interval,
                            timeout=timeout,
                            deregister=deregister)
            return cls._post_process(ret, params)
        return None