Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions build/common/installer/scripts/tomlparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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}' "
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion source/plugins/go/src/oms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/go/src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down