Package io.opencensus.resource
Class Resource
- java.lang.Object
-
- io.opencensus.resource.Resource
-
- Direct Known Subclasses:
AutoValue_Resource
@Immutable @ExperimentalApi public abstract class Resource extends java.lang.Object
Resource
represents a resource, which capture identifying information about the entities for which signals (stats or traces) are reported. It further provides a framework for detection of resource information from the environment and progressive population as signals propagate from the core instrumentation library to a backend's exporter.- Since:
- 0.18
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.String>
ENV_LABEL_MAP
private static java.lang.String
ENV_TYPE
private static java.lang.String
ERROR_MESSAGE_INVALID_CHARS
private static java.lang.String
ERROR_MESSAGE_INVALID_VALUE
private static java.lang.String
LABEL_KEY_VALUE_SPLITTER
private static java.lang.String
LABEL_LIST_SPLITTER
(package private) static int
MAX_LENGTH
private static java.lang.String
OC_RESOURCE_LABELS_ENV
private static java.lang.String
OC_RESOURCE_TYPE_ENV
-
Constructor Summary
Constructors Constructor Description Resource()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Resource
create(java.lang.String type, java.util.Map<java.lang.String,java.lang.String> labels)
Returns aResource
.static Resource
createFromEnvironmentVariables()
Returns aResource
.private static Resource
createInternal(java.lang.String type, java.util.Map<java.lang.String,java.lang.String> labels)
abstract java.util.Map<java.lang.String,java.lang.String>
getLabels()
Returns a map of labels that describe the resource.abstract java.lang.String
getType()
Returns the type identifier for the resource.private static boolean
isValid(java.lang.String name)
Determines whether the givenString
is a valid printable ASCII string with a length not exceedMAX_LENGTH
characters.private static boolean
isValidAndNotEmpty(java.lang.String name)
Determines whether the givenString
is a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTH
characters.private static Resource
merge(Resource resource, Resource otherResource)
Returns a new, mergedResource
by merging two resources.static Resource
mergeResources(java.util.List<Resource> resources)
Returns aResource
that runs all input resources sequentially and merges their results.(package private) static java.util.Map<java.lang.String,java.lang.String>
parseResourceLabels(java.lang.String rawEnvLabels)
(package private) static java.lang.String
parseResourceType(java.lang.String rawEnvType)
Creates a resource type from the OC_RESOURCE_TYPE environment variable.
-
-
-
Field Detail
-
MAX_LENGTH
static final int MAX_LENGTH
- See Also:
- Constant Field Values
-
OC_RESOURCE_TYPE_ENV
private static final java.lang.String OC_RESOURCE_TYPE_ENV
- See Also:
- Constant Field Values
-
OC_RESOURCE_LABELS_ENV
private static final java.lang.String OC_RESOURCE_LABELS_ENV
- See Also:
- Constant Field Values
-
LABEL_LIST_SPLITTER
private static final java.lang.String LABEL_LIST_SPLITTER
- See Also:
- Constant Field Values
-
LABEL_KEY_VALUE_SPLITTER
private static final java.lang.String LABEL_KEY_VALUE_SPLITTER
- See Also:
- Constant Field Values
-
ERROR_MESSAGE_INVALID_CHARS
private static final java.lang.String ERROR_MESSAGE_INVALID_CHARS
- See Also:
- Constant Field Values
-
ERROR_MESSAGE_INVALID_VALUE
private static final java.lang.String ERROR_MESSAGE_INVALID_VALUE
- See Also:
- Constant Field Values
-
ENV_TYPE
@Nullable private static final java.lang.String ENV_TYPE
-
ENV_LABEL_MAP
private static final java.util.Map<java.lang.String,java.lang.String> ENV_LABEL_MAP
-
-
Method Detail
-
getType
@Nullable public abstract java.lang.String getType()
Returns the type identifier for the resource.- Returns:
- the type identifier for the resource.
- Since:
- 0.18
-
getLabels
public abstract java.util.Map<java.lang.String,java.lang.String> getLabels()
Returns a map of labels that describe the resource.- Returns:
- a map of labels.
- Since:
- 0.18
-
createFromEnvironmentVariables
public static Resource createFromEnvironmentVariables()
Returns aResource
. This resource information is loaded from the OC_RESOURCE_TYPE and OC_RESOURCE_LABELS environment variables.- Returns:
- a
Resource
. - Since:
- 0.18
-
create
public static Resource create(@Nullable java.lang.String type, java.util.Map<java.lang.String,java.lang.String> labels)
Returns aResource
.- Parameters:
type
- the type identifier for the resource.labels
- a map of labels that describe the resource.- Returns:
- a
Resource
. - Throws:
java.lang.NullPointerException
- iflabels
is null.java.lang.IllegalArgumentException
- if type or label key or label value is not a valid printable ASCII string or exceedMAX_LENGTH
characters.- Since:
- 0.18
-
mergeResources
@Nullable public static Resource mergeResources(java.util.List<Resource> resources)
Returns aResource
that runs all input resources sequentially and merges their results. In case a type of label key is already set, the first set value takes precedence.- Parameters:
resources
- a list of resources.- Returns:
- a
Resource
. - Since:
- 0.18
-
createInternal
private static Resource createInternal(@Nullable java.lang.String type, java.util.Map<java.lang.String,java.lang.String> labels)
-
parseResourceType
@Nullable static java.lang.String parseResourceType(@Nullable java.lang.String rawEnvType)
Creates a resource type from the OC_RESOURCE_TYPE environment variable.OC_RESOURCE_TYPE: A string that describes the type of the resource prefixed by a domain namespace, e.g. “kubernetes.io/container”.
-
parseResourceLabels
static java.util.Map<java.lang.String,java.lang.String> parseResourceLabels(@Nullable java.lang.String rawEnvLabels)
-
merge
@Nullable private static Resource merge(@Nullable Resource resource, @Nullable Resource otherResource)
Returns a new, mergedResource
by merging two resources. In case of a collision, first resource takes precedence.
-
isValid
private static boolean isValid(java.lang.String name)
Determines whether the givenString
is a valid printable ASCII string with a length not exceedMAX_LENGTH
characters.- Parameters:
name
- the name to be validated.- Returns:
- whether the name is valid.
-
isValidAndNotEmpty
private static boolean isValidAndNotEmpty(java.lang.String name)
Determines whether the givenString
is a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTH
characters.- Parameters:
name
- the name to be validated.- Returns:
- whether the name is valid.
-
-