Skip to main content

version.go - Overview

  1. Overview This file defines the data structures and constants related to configuration versions and their deployment status within an agent configuration system. It includes definitions for element types, deployment statuses, and the ConfigVersion struct, along with functions to create and update configuration versions.

  2. Detailed Documentation

ElementTypeDef

  • Purpose: ElementTypeDef is a custom type representing the type of configuration element.
type ElementTypeDef string

Constants:

  • ElementTypeSamplingRules: Represents sampling rules configuration.
  • ElementTypeDropRules: Represents drop rules configuration.
  • ElementTypeLogPipelines: Represents log pipelines configuration.
  • ElementTypeLbExporter: Represents load balancer exporter configuration.

DeployStatus

  • Purpose: DeployStatus is a custom type representing the deployment status of a configuration.
type DeployStatus string

Constants:

  • PendingDeploy: Represents a pending deployment status ("DIRTY").
  • Deploying: Represents an ongoing deployment status.
  • Deployed: Represents a successful deployment status.
  • DeployInitiated: Represents a deployment that has been initiated ("IN_PROGRESS").
  • DeployFailed: Represents a failed deployment status.
  • DeployStatusUnknown: Represents an unknown deployment status.

ConfigVersion

  • Purpose: ConfigVersion struct holds the data for a specific version of a configuration element.
type ConfigVersion struct {
ID string `json:"id" db:"id"`
Version int `json:"version" db:"version"`
ElementType ElementTypeDef `json:"elementType" db:"element_type"`
Active bool `json:"active" db:"active"`
IsValid bool `json:"is_valid" db:"is_valid"`
Disabled bool `json:"disabled" db:"disabled"`

DeployStatus DeployStatus `json:"deployStatus" db:"deploy_status"`
DeployResult string `json:"deployResult" db:"deploy_result"`

LastHash string `json:"lastHash" db:"last_hash"`
LastConf string `json:"lastConf" db:"last_config"`

CreatedBy string `json:"createdBy" db:"created_by"`
CreatedByName string `json:"createdByName" db:"created_by_name"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
}
  • Fields:
    • ID: A unique identifier for the configuration version (string).
    • Version: The version number of the configuration (int).
    • ElementType: The type of configuration element (ElementTypeDef).
    • Active: Indicates if the configuration version is active (bool).
    • IsValid: Indicates if the configuration version is valid (bool).
    • Disabled: Indicates if the configuration version is disabled (bool).
    • DeployStatus: The deployment status of the configuration version (DeployStatus).
    • DeployResult: The result of the deployment (string).
    • LastHash: The hash of the last configuration (string).
    • LastConf: The last configuration in string format (string).
    • CreatedBy: The user ID who created the configuration version (string).
    • CreatedByName: The name of the user who created the configuration version (string).
    • CreatedAt: The timestamp when the configuration version was created (time.Time).

NewConfigVersion

  • Purpose: Creates a new ConfigVersion instance with default values.
func NewConfigVersion(typeDef ElementTypeDef) *ConfigVersion {
return &ConfigVersion{
ID: uuid.NewString(),
ElementType: typeDef,
Active: false,
IsValid: false,
Disabled: false,
DeployStatus: PendingDeploy,
LastHash: "",
LastConf: "{}",
// todo: get user id from context?
// CreatedBy
}
}
  • Parameters:
    • typeDef: The ElementTypeDef for the new configuration version.
  • Returns: A pointer to the newly created ConfigVersion instance.

updateVersion

  • Purpose: Increments the version number by 1.
func updateVersion(v int) int {
return v + 1
}
  • Parameters:
    • v: The current version number (int).
  • Returns: The incremented version number (int).

ConfigElements

  • Purpose: ConfigElements struct seems to represent the association between a config version and a specific element.
type ConfigElements struct {
VersionID string
Version int
ElementType ElementTypeDef
ElementId string
}
  • Fields:
    • VersionID: The ID of the configuration version (string).
    • Version: The version number (int).
    • ElementType: The type of element (ElementTypeDef).
    • ElementId: The ID of the element (string).
  1. Code Examples N/A

  2. Clarity and Accuracy The documentation reflects the code accurately.

  3. Markdown & MDX Perfection The markdown is correctly formatted.

  4. Edge Cases To Avoid Breaking MDX All potential MDX issues have been addressed.

  5. Getting Started Relevance Include in Getting Started: NO