Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Make the metdata structure more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Mar 22, 2018
1 parent 9b054d4 commit f68f858
Showing 1 changed file with 50 additions and 29 deletions.
79 changes: 50 additions & 29 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,81 @@ var (
DefaultStagedMetadata StagedMetadata
)

// ProcessingMode dictates how a metric should be processed.
type ProcessingMode int
// PipelineType describes the type of a pipeline.
type PipelineType int

// A list of supported processing mode.
// A list of supported pipeline types.
const (
// In standard mode, a metric is always processed (e.g., written to downstream)
// locally. Additionally, the metric is forwarded as necessary if there are
// more pipeline steps to complete.
StandardMode ProcessingMode = iota

// In forwarding mode, a metric is always forwarded as necessary if there are
// more pipeline steps to complete. It is only processed locally if there are
// no more pipeline stpes to complete.
ForwardingMode
// A standard pipeline is a full pipeline that has not been processed.
// The first step of a standard pipeline is always an aggregation step.
// Metrics associated with a standard pipeline are raw, unaggregated metrics.
StandardType PipelineType = iota

// A forwarding pipeline is a sub-pipeline whose previous steps have
// been processed. There are no aggregation steps in a forwarding pipeline.
// Metrics associated with a forwarding pipeline are produced from
// previous steps of the same forwarding pipeline.
ForwardingType
)

// AggregationPolicyMetadata contains metadata around how
// metrics should be aggregated and stored.
type AggregationPolicyMetadata struct {
// AggregationMetadata dictates how metrics should be aggregated.
type AggregationMetadata struct {
// List of aggregation types.
AggregationID aggregation.ID

// List of storage policies.
StoragePolicies []policy.StoragePolicy
}

// IsDefault returns whether this is the default aggregation policy metadata.
func (m AggregationPolicyMetadata) IsDefault() bool {
// IsDefault returns whether this is the default aggregation metadata.
func (m AggregationMetadata) IsDefault() bool {
return m.AggregationID.IsDefault() && policy.IsDefaultStoragePolicies(m.StoragePolicies)
}

// PipelineMetadata contains pipeline metadata.
type PipelineMetadata struct {
// StandardPipelineMetadata contains standard pipeline metadata.
type StandardPipelineMetadata struct {
AggregationMetadata
applied.Pipeline
}

// List of storage policies.
StoragePolicies []policy.StoragePolicy
// IsDefault returns whether this is the default standard pipeline metadata.
func (sm StandardPipelineMetadata) IsDefault() bool {
return sm.AggregationMetadata.IsDefault() && sm.Pipeline.IsEmpty()
}

// ForwardingPipelineMetadata contains forwarding pipeline metadata.
type ForwardingPipelineMetadata struct {
applied.Pipeline
}

// IsDefault returns whether this is the default forwarding pipeline metadata.
func (fm ForwardingPipelineMetadata) IsDefault() bool {
return fm.Pipeline.IsEmpty()
}

// PipelineMetadataUnion is a union of different pipeline metadatas.
type PipelineMetadataUnion struct {
Type PipelineType
Standard []StandardPipelineMetadata
Forwarding ForwardingPipelineMetadata
}

// IsDefault returns whether this is the default pipeline metadata.
func (pu PipelineMetadataUnion) IsDefault() bool {
return (pu.Type == StandardType && len(pu.Standard) == 0) ||
(pu.Type == ForwardingType && pu.Forwarding.IsDefault())
}

// Metadata represents the metadata associated with a metric.
type Metadata struct {
// Mode dictates how the associated metric should be processed.
Mode ProcessingMode

// Current controls the aggregation and storage plicies at the current step.
Current AggregationPolicyMetadata
AggregationMetadata

// Pipelines contain the processing pipelines the metric is subject to.
Pipelines []PipelineMetadata
Pipeline PipelineMetadataUnion
}

// IsDefault returns whether this is the default metadata.
func (m Metadata) IsDefault() bool {
return m.Mode == StandardMode && m.Current.IsDefault() && len(m.Pipelines) == 0
return m.AggregationMetadata.IsDefault() && m.Pipeline.IsDefault()
}

// ForwardMetadata represents the metadata information associated with forwarded metrics.
Expand Down

0 comments on commit f68f858

Please sign in to comment.