atmos.GomplateDatasource
The atmos.GomplateDatasource
template function wraps the Gomplate Datasources
and caches the results, allowing executing the same data source many times without calling the external endpoint multiple times.
It speeds up the data source execution and stack processing, and can eliminate other issues with calling an external endpoint,
e.g. timeouts and rate limiting.
Usage
{{ (atmos.GomplateDatasource "<alias>").<attribute> }}
Arguments
alias
- The datasource alias
attribute
- Attribute name (field) from the datasource
Caching the result of atmos.GomplateDatasource
function
Atmos caches (in memory) the results of atmos.GomplateDatasource
template function execution.
If you execute the function for the same datasource alias more than once, the first execution will call the external endpoint,
produce the result and cache it. All the consecutive calls will just use the cached data. This is useful when you use the
atmos.GomplateDatasource
function for the same datasource alias in multiple places in Atmos stack manifests.
It will speed up the function execution and stack processing.
For example:
In the example, we define a gomplate
datasource ip
and specify an external endpoint in the url
parameter.
We use the Gomplate datasource
function in the tag test1
,
and the atmos.GomplateDatasource
wrapper for the same datasource alias ip
in the other tags. The atmos.GomplateDatasource
wrapper will call the same external endpoint, but will cache the result and reuse it between the datasource invocations.
When processing the component test
from the above example, Atmos does the following:
-
Executes the
{{ (datasource "ip").ip }}
template. It calls the external endpoint using the HTTP protocol and assign theip
attribute from the result to the tagtest1
-
Executes the
{{ (atmos.GomplateDatasource "ip").ip }}
template. It calls the external endpoint again, caches the result in memory, and assigns theip
attribute from the result to the tagtest2
-
Executes the
{{ (atmos.GomplateDatasource "ip").ip }}
two more times for the tagstest3
andtest4
. It detects that the result for the same datasource aliasip
is already presend in the memory cache and reuses it without calling the external endpoint two more times
The datasource result caching makes the stack processing much faster and significantly reduces the load on external endpoints, preventing such issues as timeouts and rate limiting.