github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/tools/autoscaling/concepts/plugins/target.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: Target Plugins
     4  description: Learn how to author a Nomad Autoscaler Target plugin.
     5  ---
     6  
     7  # Target Plugins
     8  
     9  Target plugins are used by the autoscaler to retrieve information about a
    10  scaling target and also to perform a scaling action against them.
    11  
    12  For a real-world example of a Nomad Target plugin implementation, see the
    13  [Nomad `group->count` plugin][nomad_group_count_plugin].
    14  
    15  ## Authoring Target Plugins
    16  
    17  Authoring a target plugin in Go can be accomplished by implementing the
    18  [`target.Target`][target_plugin] interface, alongside a `main` package to
    19  launch the plugin.
    20  
    21  The [`no-op` Target plugin][noop_plugin] can be used as a starting point for new Target
    22  plugins.
    23  
    24  ## Target Plugin API
    25  
    26  The [base plugin][base_plugin] interface must be implemented in addition to the
    27  following functions.
    28  
    29  #### `Scale(action sdk.ScalingAction, config map[string]string) error`
    30  
    31  The `Scale` method is called by the agent during policy evaluation. The `action`
    32  argument specifies the [details][scaling_action_sdk] about the scaling action
    33  that should be made against the target. `config` includes the details about the
    34  scaling target that were provided in the [scaling policy][policy_target].
    35  
    36  #### `Status(config map[string]string) (*sdk.TargetStatus, error)`
    37  
    38  The `Status` method is called by the agent in order to determine the current
    39  status of a scaling target. This is performed as part of policy evaluation,
    40  and the [information][target_status_sdk] returned may be used by the scaling
    41  strategy to inform the next scaling action. Information returned includes
    42  current scaling level, readiness, and arbitrary metadata.
    43  
    44  [nomad_group_count_plugin]: https://github.com/hashicorp/nomad-autoscaler/tree/v0.3.0/plugins/builtin/target/nomad
    45  [target_plugin]: https://github.com/hashicorp/nomad-autoscaler/blob/v0.3.0/plugins/target/target.go#L12
    46  [base_plugin]: /tools/autoscaling/internals/plugins/base
    47  [noop_plugin]: https://github.com/hashicorp/nomad-autoscaler/tree/v0.3.0/plugins/test/noop-target
    48  [scaling_action_sdk]: https://github.com/hashicorp/nomad-autoscaler/blob/v0.3.0/sdk/strategy.go#L25
    49  [policy_target]: /tools/autoscaling/policy#target
    50  [target_status_sdk]: https://github.com/hashicorp/nomad-autoscaler/blob/v0.3.0/sdk/target.go#L6