Esempio n. 1
0
        private IOutputPlugin CreateOutputPlugin(string pluginType, string systemName, IConfigurationSection configurationSection)
        {
            _logger.SLT00013_Debug_Create_Output_pluginType_plugin_SystemName_systemName(pluginType, systemName);
            _logger.SLT00019_Trace_Main_buffer_settings_config_bufferSettingsConfig(_bufferSettingsConfig);

            if (pluginType == "Clickhouse")
            {
                var clickHousePluginConfig = new ClickhouseOutputConfig();

                configurationSection.Bind(clickHousePluginConfig);
                _logger.SLT00022_Trace_Plugin_output_config_clickHousePluginConfig(clickHousePluginConfig);

                if (clickHousePluginConfig.BufferSettings == null)
                {
                    clickHousePluginConfig.BufferSettings = _bufferSettingsConfig;
                    _logger.SLT00020_Debug_Child_settings_empty_Parent_config_is_applied();
                }
                else
                {
                    clickHousePluginConfig.BufferSettings.JoinWithParentBufferConfig(_bufferSettingsConfig);
                    _logger.SLT00021_Debug_Child_and_parent_settings_merged();
                }

                return(new ClickhouseOutputPlugin(clickHousePluginConfig, _metrics, _loggerFactory));
            }

            if (pluginType == "Forward")
            {
                var forwardOutputConfig = new ForwardOutputConfig();

                configurationSection.Bind(forwardOutputConfig);
                _logger.SLT00023_Trace_Plugin_output_config_forwardOutputConfig(forwardOutputConfig);

                if (forwardOutputConfig.BufferSettings == null)
                {
                    forwardOutputConfig.BufferSettings = _bufferSettingsConfig;
                    _logger.SLT00024_Debug_Child_settings_empty_Parent_config_is_applied();
                }
                else
                {
                    forwardOutputConfig.BufferSettings.JoinWithParentBufferConfig(_bufferSettingsConfig);
                    _logger.SLT00025_Debug_Child_and_parent_settings_merged();
                }

                return(new ForwardOutputPlugin(forwardOutputConfig, _loggerFactory));
            }

            return(null);
        }
Esempio n. 2
0
        public ClickhouseOutputPlugin(ClickhouseOutputConfig outputConfig, ILogMetrics metrics,
                                      ILoggerFactory loggerFactory) : base(
                outputConfig.System, metrics, outputConfig?.BufferSettings, loggerFactory)
        {
            _loggerFactory = loggerFactory;
            _logger        = _loggerFactory.CreateLogger <ClickhouseOutputPlugin>();

            _logger.SLT00018_Debug_ClickhouseOutputPlugin_outputConfig_outputConfig(outputConfig);

            _outputConfig = outputConfig;
            _metrics      = metrics;
            _columns      = outputConfig.Columns;

            var columns = new Dictionary <string, int>();

            foreach (var column in outputConfig.Columns)
            {
                columns[column] = columns.Count;
            }

            //_insertQuery = $"INSERT INTO {outputConfig.Database}.{outputConfig.Table} ({string.Join(", ", outputConfig.Columns)}) FORMAT Values ";
            _insertJsonQuery = $"INSERT INTO {outputConfig.Database}.{outputConfig.Table} FORMAT JSONEachRow ";
            //_formatter = new RowFormatter(columns);

            var urlBuilder = new UriBuilder("http", outputConfig.Host, outputConfig.Port);
            var properties = new Dictionary <string, string>();

            if (outputConfig.User != null)
            {
                properties.Add("user", outputConfig.User);
            }

            if (outputConfig.Password != null)
            {
                properties.Add("password", outputConfig.Password);
            }

            properties.Add("input_format_null_as_default", "1");

            _queryUrl = QueryHelpers.AddQueryString(urlBuilder.ToString(), properties);
        }