github.com/m3db/m3@v1.5.0/src/query/storage/m3/storagemetadata/attributes.go (about)

     1  // Copyright (c) 2022 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package storagemetadata
    22  
    23  import (
    24  	"fmt"
    25  	"time"
    26  )
    27  
    28  // MetricsType is a type of stored metrics.
    29  type MetricsType uint
    30  
    31  const (
    32  	// UnknownMetricsType is the unknown metrics type and is invalid.
    33  	UnknownMetricsType MetricsType = iota
    34  	// UnaggregatedMetricsType is an unaggregated metrics type.
    35  	UnaggregatedMetricsType
    36  	// AggregatedMetricsType is an aggregated metrics type.
    37  	AggregatedMetricsType
    38  
    39  	// DefaultMetricsType is the default metrics type value.
    40  	DefaultMetricsType = UnaggregatedMetricsType
    41  )
    42  
    43  // Attributes is a set of stored metrics attributes.
    44  type Attributes struct {
    45  	// MetricsType indicates the type of namespace this metric originated from.
    46  	MetricsType MetricsType
    47  	// Retention indicates the retention of the namespace this metric originated
    48  	// from.
    49  	Retention time.Duration
    50  	// Resolution indicates the retention of the namespace this metric originated
    51  	// from.
    52  	Resolution time.Duration
    53  }
    54  
    55  // Validate validates a storage attributes.
    56  func (a Attributes) Validate() error {
    57  	return ValidateMetricsType(a.MetricsType)
    58  }
    59  
    60  // String returns a string detailing the attributes.
    61  func (a Attributes) String() string {
    62  	return fmt.Sprintf("type=%s, retention=%s, resolution=%s",
    63  		a.MetricsType.String(),
    64  		a.Retention.String(),
    65  		a.Resolution.String())
    66  }
    67  
    68  // CombinedWith returns these Attributes combined with other Attributes.
    69  func (a Attributes) CombinedWith(other Attributes) Attributes {
    70  	metricType := a.MetricsType
    71  	if other.MetricsType == AggregatedMetricsType {
    72  		metricType = AggregatedMetricsType
    73  	}
    74  
    75  	maxResolution := a.Resolution
    76  	if other.Resolution > maxResolution {
    77  		maxResolution = other.Resolution
    78  	}
    79  
    80  	maxRetention := a.Retention
    81  	if other.Retention > maxRetention {
    82  		maxRetention = other.Retention
    83  	}
    84  
    85  	return Attributes{
    86  		MetricsType: metricType,
    87  		Resolution:  maxResolution,
    88  		Retention:   maxRetention,
    89  	}
    90  }