Skip to main content

weekly.go

weekly.go - Overview

  1. Overview This file defines the WeeklyProvider struct and its associated methods for detecting weekly anomalies. It leverages a base seasonal provider and configures a querier for fetching data.

  2. Detailed Documentation

WeeklyProvider

  • Purpose: Struct for providing weekly anomaly detection functionality. It embeds BaseSeasonalProvider to inherit common seasonal anomaly detection logic.
type WeeklyProvider struct {
BaseSeasonalProvider
}

(*WeeklyProvider) GetBaseSeasonalProvider

  • Purpose: Returns a pointer to the embedded BaseSeasonalProvider.
  • Returns: *BaseSeasonalProvider - A pointer to the base seasonal provider.
func (wp *WeeklyProvider) GetBaseSeasonalProvider() *BaseSeasonalProvider {
return &wp.BaseSeasonalProvider
}

NewWeeklyProvider

  • Purpose: Creates a new WeeklyProvider instance. It accepts functional options for configuration and initializes the embedded querier.
  • Parameters:
    • opts ...GenericProviderOption[*WeeklyProvider]: A variadic list of functional options to configure the WeeklyProvider.
  • Returns: *WeeklyProvider - A pointer to the newly created WeeklyProvider instance.
func NewWeeklyProvider(opts ...GenericProviderOption[*WeeklyProvider]) *WeeklyProvider {
wp := &WeeklyProvider{
BaseSeasonalProvider: BaseSeasonalProvider{},
}

for _, opt := range opts {
opt(wp)
}

wp.querierV2 = querierV2.NewQuerier(querierV2.QuerierOptions{
Reader: wp.reader,
Cache: wp.cache,
KeyGenerator: queryBuilder.NewKeyGenerator(),
FluxInterval: wp.fluxInterval,
FeatureLookup: wp.ff,
})

return wp
}

(*WeeklyProvider) GetAnomalies

  • Purpose: Retrieves anomalies based on weekly seasonality. It sets the Seasonality field in the request to SeasonalityWeekly and then calls the getAnomalies method (inherited from BaseSeasonalProvider) to perform the actual anomaly detection.
  • Parameters:
    • ctx context.Context: The context for the request.
    • req *GetAnomaliesRequest: The request object containing parameters for anomaly detection.
  • Returns: *GetAnomaliesResponse - The response object containing the detected anomalies, and error if there was an error during the process.
func (p *WeeklyProvider) GetAnomalies(ctx context.Context, req *GetAnomaliesRequest) (*GetAnomaliesResponse, error) {
req.Seasonality = SeasonalityWeekly
return p.getAnomalies(ctx, req)
}

Include in Getting Started: NO