示例#1
0
    def _get_metrics_registry(self):
        clients = []
        use_logger, use_stackdriver = None, None
        metrics_config = self.config.job_config.metrics

        # use_logger and use_stackdriver could be False (turn off),
        # None (use default config), or a dict of configured values
        use_logger = metrics_config.get("logger")
        use_stackdriver = metrics_config.get("stackdriver_logger")

        # TODO: set runner in OS environment (via klio-exec), since
        #       the runner defined in config could be overwritten via
        #       `--direct-runner`.
        #       i.e.: runner = os.getenv("BEAM_RUNNER", "").lower()
        runner = self.config.pipeline_options.runner
        if "dataflow" in runner.lower():
            # Must explicitly compare to `False` since `None` could be
            # the user accepting default config.
            # If explicitly false, then just disable logger underneath SD
            if use_stackdriver is not False:
                sd_client = stackdriver.StackdriverLogMetricsClient(
                    self.config
                )
                clients.append(sd_client)
            else:
                # if use_stackdriver is explicitly false, then make sure
                # logger client is disabled since the stackdriver client
                # inherits the logger client
                use_logger = False

        if not len(clients):  # setup default client
            disabled = False
            # User might disable the logger, but we still need a relay
            # client if all other relay clients are disabled. This allows
            # folks to silence metrics but not need to remove code that
            # interacts with `_klio.metrics`.
            # Must explicitly compare to `False` since `None` could be
            # the user accepting default config
            if use_logger is False:
                disabled = True
            logger_client = metrics_logger.MetricsLoggerClient(
                self.config, disabled=disabled
            )
            clients.append(logger_client)

        return metrics_client.MetricsRegistry(
            clients, transform_name=self._transform_name
        )
示例#2
0
def client(klio_config, monkeypatch, mocker, mock_stackdriver_client):
    return sd_metrics.StackdriverLogMetricsClient(klio_config)