func (did *DockerInfoDetail) FindAllEnvConfig(envConfigPrefix string, selfConfigFlag bool) {

	if len(envConfigPrefix) == 0 {
		return
	}
	selfEnvConfig := false
	for _, env := range did.ContainerInfo.Config.Env {
		kvPair := strings.SplitN(env, "=", 2)
		if len(kvPair) != 2 {
			continue
		}
		key := kvPair[0]
		value := kvPair[1]

		if key == "ALICLOUD_LOG_DOCKER_ENV_CONFIG_SELF" && (value == "true" || value == "TRUE") {
			logger.Debug(context.Background(), "this container is self env config", did.ContainerInfo.Name)
			selfEnvConfig = true
			continue
		}

		if !strings.HasPrefix(key, envConfigPrefix) {
			continue
		}
		logger.Debug(context.Background(), "docker env config, name", did.ContainerInfo.Name, "item", key)
		envKey := key[len(envConfigPrefix):]
		lastIndex := strings.LastIndexByte(envKey, '_')
		var configName string
		// end with '_', invalid, just skip
		if lastIndex == len(envKey)-1 {
			continue
		}

		// raw config
		if lastIndex < 0 {
			configName = envKey
		} else {
			configName = envKey[0:lastIndex]
		}
		// invalid config name
		if len(configName) == 0 {
			continue
		}
		envConfig := did.MakeSureEnvConfigExist(configName)
		if lastIndex < 0 {
			envConfig.ConfigItemMap[""] = value
		} else {
			tailKey := envKey[lastIndex+1:]
			envConfig.ConfigItemMap[tailKey] = value
			// process tags
			if tailKey == "tags" {
				tagKV := strings.SplitN(value, "=", 2)
				// if tag exist in EnvTags, just skip this tag
				if len(tagKV) == 2 {
					if !HasEnvTags(tagKV[0], tagKV[1]) {
						did.ContainerNameTag[tagKV[0]] = tagKV[1]
					} else {
						logger.Info(context.Background(), "skip set this tag, as this exist in self env tags, key", tagKV[0], "value", tagKV[1])
					}
				} else {
					if !HasEnvTags(tagKV[0], tagKV[0]) {
						did.ContainerNameTag[tagKV[0]] = tagKV[0]
					} else {
						logger.Info(context.Background(), "skip set this tag, as this exist in self env tags, key&value", tagKV[0])
					}
				}
			}
		}
	}
	logger.Debug(context.Background(), "docker env", did.ContainerInfo.Config.Env, "prefix", envConfigPrefix, "env config", did.EnvConfigInfoMap, "self env config", selfEnvConfig)
	// ignore self env config
	if !selfConfigFlag && selfEnvConfig {
		did.EnvConfigInfoMap = make(map[string]*EnvConfigInfo)
	}
}
// FindAllEnvConfig find and pre process all env config, add tags for docker info
FindAllEnvConfig find and pre process all env config, add tags for docker info
// FindAllEnvConfig find and pre process all env config add tags for docker info
func (did *DockerInfoDetail) FindAllEnvConfig(envConfigPrefix string, selfConfigFlag bool) {
	if len(envConfigPrefix) == 0 {
		return
	}
	selfEnvConfig := false
	for _, env := range did.ContainerInfo.Config.Env {
		kvPair := strings.SplitN(env, "=", 2)
		if len(kvPair) != 2 {
			continue
		}
		key := kvPair[0]
		value := kvPair[1]
		if key == "ALICLOUD_LOG_DOCKER_ENV_CONFIG_SELF" && (value == "true" || value == "TRUE") {
			logger.Debug(context.Background(), "this container is self env config", did.ContainerInfo.Name)
			selfEnvConfig = true
			continue
		}
		if !strings.HasPrefix(key, envConfigPrefix) {
			continue
		}
		logger.Debug(context.Background(), "docker env config, name", did.ContainerInfo.Name, "item", key)
		envKey := key[len(envConfigPrefix):]
		lastIndex := strings.LastIndexByte(envKey, '_')
		var configName string
		if lastIndex == len(envKey)-1 {
			continue
		}
		if lastIndex < 0 {
			configName = envKey
		} else {
			configName = envKey[0:lastIndex]
		}
		if len(configName) == 0 {
			continue
		}
		envConfig := did.MakeSureEnvConfigExist(configName)
		if lastIndex < 0 {
			envConfig.ConfigItemMap[""] = value
		} else {
			tailKey := envKey[lastIndex+1:]
			envConfig.ConfigItemMap[tailKey] = value
			if tailKey == "tags" {
				tagKV := strings.SplitN(value, "=", 2)
				if len(tagKV) == 2 {
					if !HasEnvTags(tagKV[0], tagKV[1]) {
						did.ContainerNameTag[tagKV[0]] = tagKV[1]
					} else {
						logger.Info(context.Background(), "skip set this tag, as this exist in self env tags, key", tagKV[0], "value", tagKV[1])
					}
				} else {
					if !HasEnvTags(tagKV[0], tagKV[0]) {
						did.ContainerNameTag[tagKV[0]] = tagKV[0]
					} else {
						logger.Info(context.Background(), "skip set this tag, as this exist in self env tags, key&value", tagKV[0])
					}
				}
			}
		}
	}
	logger.Debug(context.Background(), "docker env", did.ContainerInfo.Config.Env, "prefix", envConfigPrefix, "env config", did.EnvConfigInfoMap, "self env config", selfEnvConfig)
	if !selfConfigFlag && selfEnvConfig {
		did.EnvConfigInfoMap = make(map[string]*EnvConfigInfo)
	}
}
func ( did * DockerInfoDetail ) FindAllEnvConfig ( envConfigPrefix string , selfConfigFlag bool ) { if len ( envConfigPrefix ) == 0 { return } selfEnvConfig := false for _ , env := range did . ContainerInfo . Config . Env { kvPair := strings . SplitN ( env , " " , 2 ) if len ( kvPair ) != 2 { continue } key := kvPair [ 0 ] value := kvPair [ 1 ] if key == " " && ( value == " " || value == " " ) { logger . Debug ( context . Background ( ) , " " , did . ContainerInfo . Name ) selfEnvConfig = true continue } if ! strings . HasPrefix ( key , envConfigPrefix ) { continue } logger . Debug ( context . Background ( ) , " " , did . ContainerInfo . Name , " " , key ) envKey := key [ len ( envConfigPrefix ) : ] lastIndex := strings . LastIndexByte ( envKey , '_' ) var configName string if lastIndex == len ( envKey ) - 1 { continue } if lastIndex < 0 { configName = envKey } else { configName = envKey [ 0 : lastIndex ] } if len ( configName ) == 0 { continue } envConfig := did . MakeSureEnvConfigExist ( configName ) if lastIndex < 0 { envConfig . ConfigItemMap [ " " ] = value } else { tailKey := envKey [ lastIndex + 1 : ] envConfig . ConfigItemMap [ tailKey ] = value if tailKey == " " { tagKV := strings . SplitN ( value , " " , 2 ) if len ( tagKV ) == 2 { if ! HasEnvTags ( tagKV [ 0 ] , tagKV [ 1 ] ) { did . ContainerNameTag [ tagKV [ 0 ] ] = tagKV [ 1 ] } else { logger . Info ( context . Background ( ) , " " , tagKV [ 0 ] , " " , tagKV [ 1 ] ) } } else { if ! HasEnvTags ( tagKV [ 0 ] , tagKV [ 0 ] ) { did . ContainerNameTag [ tagKV [ 0 ] ] = tagKV [ 0 ] } else { logger . Info ( context . Background ( ) , " " , tagKV [ 0 ] ) } } } } } logger . Debug ( context . Background ( ) , " " , did . ContainerInfo . Config . Env , " " , envConfigPrefix , " " , did . EnvConfigInfoMap , " " , selfEnvConfig ) if ! selfConfigFlag && selfEnvConfig { did . EnvConfigInfoMap = make ( map [ string ] * EnvConfigInfo ) } }
FindAllEnvConfig find and pre process all env config, add tags for docker info
FindAllEnvConfig find and pre process all env config add tags for docker info
// end with '_', invalid, just skip // raw config // invalid config name // process tags // if tag exist in EnvTags, just skip this tag // ignore self env config