datafeed

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

README

ML Datafeed Resource

This resource creates and manages Machine Learning datafeeds in Elasticsearch. Datafeeds retrieve data from Elasticsearch for analysis by an anomaly detection job. Each anomaly detection job can have only one associated datafeed.

Key Features

  • Complete API Coverage: Supports all ML datafeed API options including:

    • Index patterns and queries for data retrieval
    • Aggregations for time-based data summaries
    • Chunking configuration for long time periods
    • Delayed data check configuration
    • Runtime mappings and script fields
    • Frequency and query delay settings
    • Scroll size optimization
    • Custom headers support
  • Orchestration: Manages datafeed lifecycle including:

    • Automatic stopping before updates (as required by Elasticsearch)
    • Restarting after successful updates
    • Proper cleanup on deletion
  • Validation: Comprehensive field validation including:

    • Datafeed ID format validation (lowercase alphanumeric, hyphens, underscores)
    • Duration format validation for frequency and query_delay
    • JSON validation for complex objects

Implementation Details

This resource follows the Plugin Framework architecture and includes:

  • Complete schema definition with all API fields
  • Proper model conversion between API and Terraform types
  • Comprehensive CRUD operations
  • Extensive acceptance tests
  • Import functionality for existing datafeeds

API References

Special Considerations

  1. Update Orchestration: Datafeeds must be stopped before updating and can be restarted afterward
  2. Job Association: Each datafeed is associated with exactly one anomaly detection job
  3. Index Permissions: Requires read permissions on the source indices
  4. ML Privileges: Requires manage_ml cluster privilege

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetChunkingConfigAttrTypes

func GetChunkingConfigAttrTypes() map[string]attr.Type

GetChunkingConfigAttrTypes returns the attribute types for chunking_config

func GetDelayedDataCheckConfigAttrTypes

func GetDelayedDataCheckConfigAttrTypes() map[string]attr.Type

GetDelayedDataCheckConfigAttrTypes returns the attribute types for delayed_data_check_config

func GetIndicesOptionsAttrTypes

func GetIndicesOptionsAttrTypes() map[string]attr.Type

GetIndicesOptionsAttrTypes returns the attribute types for indices_options

func GetSchema

func GetSchema() schema.Schema

func NewDatafeedResource

func NewDatafeedResource() resource.Resource

func WaitForDatafeedState

func WaitForDatafeedState(ctx context.Context, client *clients.ApiClient, datafeedId string, desiredState State) (bool, diag.Diagnostics)

WaitForDatafeedState waits for a datafeed to reach the desired state

Types

type ChunkingConfig

type ChunkingConfig struct {
	Mode     types.String `tfsdk:"mode"`
	TimeSpan types.String `tfsdk:"time_span"`
}

ChunkingConfig represents the chunking configuration

type Datafeed

type Datafeed struct {
	ID                      types.String                                      `tfsdk:"id"`
	ElasticsearchConnection types.List                                        `tfsdk:"elasticsearch_connection"`
	DatafeedID              types.String                                      `tfsdk:"datafeed_id"`
	JobID                   types.String                                      `tfsdk:"job_id"`
	Indices                 types.List                                        `tfsdk:"indices"`
	Query                   jsontypes.Normalized                              `tfsdk:"query"`
	Aggregations            jsontypes.Normalized                              `tfsdk:"aggregations"`
	ScriptFields            customtypes.JSONWithDefaultsValue[map[string]any] `tfsdk:"script_fields"`
	RuntimeMappings         jsontypes.Normalized                              `tfsdk:"runtime_mappings"`
	ScrollSize              types.Int64                                       `tfsdk:"scroll_size"`
	ChunkingConfig          types.Object                                      `tfsdk:"chunking_config"`
	Frequency               types.String                                      `tfsdk:"frequency"`
	QueryDelay              types.String                                      `tfsdk:"query_delay"`
	DelayedDataCheckConfig  types.Object                                      `tfsdk:"delayed_data_check_config"`
	MaxEmptySearches        types.Int64                                       `tfsdk:"max_empty_searches"`
	IndicesOptions          types.Object                                      `tfsdk:"indices_options"`
}

Datafeed represents the Terraform resource model for ML datafeeds

func (*Datafeed) FromAPIModel

func (m *Datafeed) FromAPIModel(ctx context.Context, apiModel *models.Datafeed) fwdiags.Diagnostics

FromAPIModel populates the Terraform model from an API model

func (*Datafeed) ToAPIModel

func (m *Datafeed) ToAPIModel(ctx context.Context) (*models.Datafeed, fwdiags.Diagnostics)

ToAPIModel converts the Terraform model to an API model for creating/updating

type DelayedDataCheckConfig

type DelayedDataCheckConfig struct {
	Enabled     types.Bool   `tfsdk:"enabled"`
	CheckWindow types.String `tfsdk:"check_window"`
}

DelayedDataCheckConfig represents the delayed data check configuration

type IndicesOptions

type IndicesOptions struct {
	ExpandWildcards   types.List `tfsdk:"expand_wildcards"`
	IgnoreUnavailable types.Bool `tfsdk:"ignore_unavailable"`
	AllowNoIndices    types.Bool `tfsdk:"allow_no_indices"`
	IgnoreThrottled   types.Bool `tfsdk:"ignore_throttled"`
}

IndicesOptions represents the indices options for search

type State

type State string
const (
	StateStopped  State = "stopped"
	StateStarted  State = "started"
	StateStarting State = "starting"
)

func GetDatafeedState

func GetDatafeedState(ctx context.Context, client *clients.ApiClient, datafeedId string) (*State, diag.Diagnostics)

GetDatafeedState returns the current state of a datafeed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL