builtin.go
builtin.go - Overview
-
Overview This file defines the
BuiltInIntegrations
struct and related functions for managing built-in integrations. It handles reading, parsing, validating, and hydrating integration specifications from embedded files. -
Detailed Documentation
BuiltInIntegrations
- Purpose: Represents a collection of built-in integrations.
- Parameters: None
- Returns: None
(*BuiltInIntegrations) list(ctx context.Context) ([]IntegrationDetails, *model.ApiError)
- Purpose: Retrieves a sorted list of all built-in integrations.
- Parameters:
ctx
(context.Context): The context for the operation.
- Returns:
[]IntegrationDetails
: A slice ofIntegrationDetails
representing the integrations.*model.ApiError
: An error object, ornil
if no error occurred.
(*BuiltInIntegrations) get(ctx context.Context, integrationIds []string) (map[string]IntegrationDetails, *model.ApiError)
- Purpose: Retrieves specific built-in integrations based on their IDs.
- Parameters:
ctx
(context.Context): The context for the operation.integrationIds
([]string): A slice of integration IDs to retrieve.
- Returns:
map[string]IntegrationDetails
: A map of integration IDs toIntegrationDetails
objects.*model.ApiError
: An error object, ornil
if no error occurred.
integrationFiles embed.FS
- Purpose: Embeds the file system containing the built-in integration files.
- Parameters: None
- Returns: None
init()
- Purpose: Initializes the built-in integrations by reading them from the embedded file system.
- Parameters: None
- Returns: None
readBuiltIns() error
- Purpose: Reads and parses all built-in integration files.
- Parameters: None
- Returns:
error
: An error object if any error occurred during reading or parsing,nil
otherwise.
readBuiltInIntegration(dirpath string) (*IntegrationDetails, error)
- Purpose: Reads and parses a single built-in integration from a specified directory.
- Parameters:
dirpath
(string): The path to the directory containing the integration files.
- Returns:
*IntegrationDetails
: A pointer to anIntegrationDetails
object representing the integration.error
: An error object if any error occurred during reading or parsing,nil
otherwise.
validateIntegration(i IntegrationDetails) error
- Purpose: Validates the data within an
IntegrationDetails
struct, specifically dashboard IDs. - Parameters:
i
(IntegrationDetails): The integration details to validate.
- Returns:
error
: An error object if validation fails,nil
otherwise.
HydrateFileUris(spec interface{}, fs embed.FS, basedir string) (interface{}, error)
- Purpose: Hydrates file URIs within an integration specification by reading the referenced files and replacing the URIs with their contents.
- Parameters:
spec
(interface{}): The integration specification to hydrate.fs
(embed.FS): The embedded file system.basedir
(string): The base directory for resolving relative file paths.
- Returns:
interface{}
: The hydrated integration specification.error
: An error object if any error occurred during hydration,nil
otherwise.
readFileIfUri(fs embed.FS, maybeFileUri string, basedir string) (interface{}, error)
- Purpose: Reads a file from the embedded file system if the provided string is a file URI. Otherwise, returns the string as is.
- Parameters:
fs
(embed.FS): The embedded file system.maybeFileUri
(string): The string to check for a file URI prefix.basedir
(string): The base directory for resolving relative file paths.
- Returns:
interface{}
: The file contents or the original string if it's not a file URI.error
: An error object if any error occurred during reading the file,nil
otherwise.
toPromMetricName(s string) string
- Purpose: Converts a string to a valid Prometheus metric name by replacing non-alphanumeric characters with underscores.
- Parameters:
s
(string): The string to convert.
- Returns:
string
: The converted Prometheus metric name.
- Code Examples None
Include in Getting Started: NO