diff --git a/build/common/installer/scripts/tomlparser.rb b/build/common/installer/scripts/tomlparser.rb index b173ecfe3..32ea09aa3 100644 --- a/build/common/installer/scripts/tomlparser.rb +++ b/build/common/installer/scripts/tomlparser.rb @@ -26,6 +26,7 @@ @containerLogSchemaVersion = "" @collectAllKubeEvents = false @containerLogsRoute = "v2" # default for linux +@adxDatabaseName = "containerinsights" # default for all configurations if !@os_type.nil? && !@os_type.empty? && @os_type.strip.casecmp("windows") == 0 @containerLogsRoute = "v1" # default is v1 for windows until windows agent integrates windows ama end @@ -175,6 +176,23 @@ def populateSettingValuesFromConfigMap(parsedConfig) ConfigParseErrorLogger.logError("Exception while reading config map settings for container logs route - #{errorStr}, using defaults, please check config map for errors") end + #Get ADX database name setting + begin + if !parsedConfig[:log_collection_settings][:adx_database].nil? && !parsedConfig[:log_collection_settings][:adx_database][:name].nil? + if !parsedConfig[:log_collection_settings][:adx_database][:name].empty? + @adxDatabaseName = parsedConfig[:log_collection_settings][:adx_database][:name] + puts "config::Using config map setting for ADX database name : #{@adxDatabaseName}" + else + puts "config::Ignoring config map settings and using default value '#{@adxDatabaseName}' since provided adx database name value is empty" + end + else + puts "config::No ADX database name set, using default value : #{@adxDatabaseName}" + end + rescue => errorStr + ConfigParseErrorLogger.logError("Exception while reading config map settings for adx database name - #{errorStr}, using default #{@adxDatabaseName}, please check config map for errors") + end + + end end end @@ -218,6 +236,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_CLUSTER_COLLECT_ALL_KUBE_EVENTS=#{@collectAllKubeEvents}\n") file.write("export AZMON_CONTAINER_LOGS_ROUTE=#{@containerLogsRoute}\n") file.write("export AZMON_CONTAINER_LOG_SCHEMA_VERSION=#{@containerLogSchemaVersion}\n") + file.write("export AZMON_ADX_DATABASE_NAME=#{@adxDatabaseName}\n") # Close file after writing all environment variables file.close puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' " @@ -266,6 +285,8 @@ def get_command_windows(env_variable_name, env_variable_value) file.write(commands) commands = get_command_windows('AZMON_CONTAINER_LOG_SCHEMA_VERSION', @containerLogSchemaVersion) file.write(commands) + commands = get_command_windows('AZMON_ADX_DATABASE_NAME', @adxDatabaseName) + file.write(commands) # Close file after writing all environment variables file.close diff --git a/source/plugins/go/src/oms.go b/source/plugins/go/src/oms.go index 91a5b4b40..ee221a60b 100644 --- a/source/plugins/go/src/oms.go +++ b/source/plugins/go/src/oms.go @@ -117,6 +117,9 @@ const MdsdOutputStreamIdTagPrefix = "dcr-" //env variable to container type const ContainerTypeEnv = "CONTAINER_TYPE" +//Default ADX destination database name, can be overriden through configuration +const DefaultAdxDatabaseName = "containerinsights" + var ( // PluginConfiguration the plugins configuration PluginConfiguration map[string]string @@ -166,6 +169,8 @@ var ( AdxTenantID string //ADX client secret AdxClientSecret string + //ADX destination database name, default is DefaultAdxDatabaseName, can be overridden in configuration + AdxDatabaseName string // container log or container log v2 tag name for oneagent route MdsdContainerLogTagName string // kubemonagent events tag name for oneagent route @@ -1698,6 +1703,17 @@ func InitializePlugin(pluginConfPath string, agentVersion string) { ContainerLogsRouteADX = false if strings.Compare(ContainerLogsRoute, ContainerLogsADXRoute) == 0 { + // Try to read the ADX database name from environment variables. Default to DefaultAdsDatabaseName if not set. + // This SHOULD be set by tomlparser.rb so it's a highly unexpected event if it isn't. + // It should be set by the logic in tomlparser.rb EVEN if ADX logging isn't enabled + AdxDatabaseName := strings.TrimSpace(os.Getenv("AZMON_ADX_DATABASE_NAME")) + + // Check the len of the provided name for database and use default if 0, just to be sure + if len(AdxDatabaseName) == 0 { + Log("Adx database name unexpecedly empty (check config AND implementation, should have been set by tomlparser.rb?) - will default to '%s'", DefaultAdxDatabaseName) + AdxDatabaseName = DefaultAdxDatabaseName + } + //check if adx clusteruri, clientid & secret are set var err error AdxClusterUri, err = ReadFileContents(PluginConfiguration["adx_cluster_uri_path"]) @@ -1708,6 +1724,7 @@ func InitializePlugin(pluginConfPath string, agentVersion string) { Log("Invalid AdxClusterUri %s", AdxClusterUri) AdxClusterUri = "" } + AdxClientID, err = ReadFileContents(PluginConfiguration["adx_client_id_path"]) if err != nil { Log("Error when reading AdxClientID %s", err) @@ -1723,7 +1740,8 @@ func InitializePlugin(pluginConfPath string, agentVersion string) { Log("Error when reading AdxClientSecret %s", err) } - if len(AdxClusterUri) > 0 && len(AdxClientID) > 0 && len(AdxClientSecret) > 0 && len(AdxTenantID) > 0 { + // AdxDatabaseName should never get in a state where its length is 0, but it doesn't hurt to add the check + if len(AdxClusterUri) > 0 && len(AdxClientID) > 0 && len(AdxClientSecret) > 0 && len(AdxTenantID) > 0 && len(AdxDatabaseName) > 0 { ContainerLogsRouteADX = true Log("Routing container logs thru %s route...", ContainerLogsADXRoute) fmt.Fprintf(os.Stdout, "Routing container logs thru %s route...\n", ContainerLogsADXRoute) diff --git a/source/plugins/go/src/utils.go b/source/plugins/go/src/utils.go index 6b3036f85..61c6898d7 100644 --- a/source/plugins/go/src/utils.go +++ b/source/plugins/go/src/utils.go @@ -192,7 +192,7 @@ func CreateADXClient() { //log.Fatalf("Unable to create ADX connection %s", err.Error()) } else { Log("Successfully created ADX Client. Creating Ingestor...") - ingestor, ingestorErr := ingest.New(client, "containerinsights", "ContainerLogV2") + ingestor, ingestorErr := ingest.New(client, AdxDatabaseName, "ContainerLogV2") if ingestorErr != nil { Log("Error::mdsd::Unable to create ADX ingestor %s", ingestorErr.Error()) } else {