|
|
@ -13,7 +13,6 @@
|
|
|
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations under the License.
|
|
|
|
* specific language governing permissions and limitations under the License.
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.common.metadata;
|
|
|
|
package com.tencent.cloud.common.metadata;
|
|
|
@ -35,7 +34,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* manage metadata from env/config file/custom spi.
|
|
|
|
* manage metadata from env/config file/custom spi.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author lepdou 2022-05-20
|
|
|
|
* @author lepdou, Haotian Zhang
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class StaticMetadataManager {
|
|
|
|
public class StaticMetadataManager {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -55,12 +54,19 @@ public class StaticMetadataManager {
|
|
|
|
private static final int ENV_METADATA_PREFIX_LENGTH = ENV_METADATA_PREFIX.length();
|
|
|
|
private static final int ENV_METADATA_PREFIX_LENGTH = ENV_METADATA_PREFIX.length();
|
|
|
|
private static final String ENV_METADATA_CONTENT_TRANSITIVE = "SCT_METADATA_CONTENT_TRANSITIVE";
|
|
|
|
private static final String ENV_METADATA_CONTENT_TRANSITIVE = "SCT_METADATA_CONTENT_TRANSITIVE";
|
|
|
|
private static final String ENV_METADATA_CONTENT_DISPOSABLE = "SCT_METADATA_CONTENT_DISPOSABLE";
|
|
|
|
private static final String ENV_METADATA_CONTENT_DISPOSABLE = "SCT_METADATA_CONTENT_DISPOSABLE";
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This is the key of the header's key list needed to be transmitted. The list is a string split with ,.
|
|
|
|
|
|
|
|
* The value mapped by this key was specified by user.
|
|
|
|
|
|
|
|
* This is configured in environment variables.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static final String ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS = "SCT_TRAFFIC_CONTENT_RAW_TRANSHEADERS";
|
|
|
|
private static final String ENV_METADATA_ZONE = "SCT_METADATA_ZONE";
|
|
|
|
private static final String ENV_METADATA_ZONE = "SCT_METADATA_ZONE";
|
|
|
|
private static final String ENV_METADATA_REGION = "SCT_METADATA_REGION";
|
|
|
|
private static final String ENV_METADATA_REGION = "SCT_METADATA_REGION";
|
|
|
|
private static final String ENV_METADATA_CAMPUS = "SCT_METADATA_CAMPUS";
|
|
|
|
private static final String ENV_METADATA_CAMPUS = "SCT_METADATA_CAMPUS";
|
|
|
|
private Map<String, String> envMetadata;
|
|
|
|
private Map<String, String> envMetadata;
|
|
|
|
private Map<String, String> envTransitiveMetadata;
|
|
|
|
private Map<String, String> envTransitiveMetadata;
|
|
|
|
private Map<String, String> envDisposableMetadata;
|
|
|
|
private Map<String, String> envDisposableMetadata;
|
|
|
|
|
|
|
|
private Map<String, String> envNotReportMetadata;
|
|
|
|
private Map<String, String> configMetadata;
|
|
|
|
private Map<String, String> configMetadata;
|
|
|
|
private Map<String, String> configTransitiveMetadata;
|
|
|
|
private Map<String, String> configTransitiveMetadata;
|
|
|
|
private Map<String, String> configDisposableMetadata;
|
|
|
|
private Map<String, String> configDisposableMetadata;
|
|
|
@ -94,14 +100,23 @@ public class StaticMetadataManager {
|
|
|
|
Map<String, String> allEnvs = System.getenv();
|
|
|
|
Map<String, String> allEnvs = System.getenv();
|
|
|
|
|
|
|
|
|
|
|
|
envMetadata = new HashMap<>();
|
|
|
|
envMetadata = new HashMap<>();
|
|
|
|
|
|
|
|
envNotReportMetadata = new HashMap<>();
|
|
|
|
// parse all metadata
|
|
|
|
// parse all metadata
|
|
|
|
for (Map.Entry<String, String> entry : allEnvs.entrySet()) {
|
|
|
|
for (Map.Entry<String, String> entry : allEnvs.entrySet()) {
|
|
|
|
String key = entry.getKey();
|
|
|
|
String key = entry.getKey();
|
|
|
|
String value = entry.getValue();
|
|
|
|
String value = entry.getValue();
|
|
|
|
if (StringUtils.isNotBlank(key) && key.startsWith(ENV_METADATA_PREFIX)
|
|
|
|
if (StringUtils.isNotBlank(key)
|
|
|
|
|
|
|
|
&& (key.startsWith(ENV_METADATA_PREFIX) || key.equals(ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS))
|
|
|
|
&& !key.equals(ENV_METADATA_CONTENT_TRANSITIVE)) {
|
|
|
|
&& !key.equals(ENV_METADATA_CONTENT_TRANSITIVE)) {
|
|
|
|
String sourceKey = StringUtils.substring(key, ENV_METADATA_PREFIX_LENGTH);
|
|
|
|
String sourceKey = "";
|
|
|
|
envMetadata.put(sourceKey, value);
|
|
|
|
if (key.equals(ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS)) {
|
|
|
|
|
|
|
|
sourceKey = key;
|
|
|
|
|
|
|
|
envNotReportMetadata.put(sourceKey, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
sourceKey = StringUtils.substring(key, ENV_METADATA_PREFIX_LENGTH);
|
|
|
|
|
|
|
|
envMetadata.put(sourceKey, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOGGER.info("[SCT] resolve metadata from env. key = {}, value = {}", sourceKey, value);
|
|
|
|
LOGGER.info("[SCT] resolve metadata from env. key = {}, value = {}", sourceKey, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -269,6 +284,10 @@ public class StaticMetadataManager {
|
|
|
|
return envMetadata;
|
|
|
|
return envMetadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getTransHeaderFromEnv() {
|
|
|
|
|
|
|
|
return envNotReportMetadata.get(ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, String> getEnvTransitiveMetadata() {
|
|
|
|
public Map<String, String> getEnvTransitiveMetadata() {
|
|
|
|
return envTransitiveMetadata;
|
|
|
|
return envTransitiveMetadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|