go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/tsmon/types/target.go (about)

     1  // Copyright 2015 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package types
    16  
    17  import (
    18  	"fmt"
    19  	"reflect"
    20  
    21  	pb "go.chromium.org/luci/common/tsmon/ts_mon_proto"
    22  )
    23  
    24  // A Target knows how to put information about itself in a MetricsData message.
    25  type Target interface {
    26  	// TODO(1026140): the hash and proto of a Target object should be created
    27  	// at the time of the object creation.
    28  	PopulateProto(d *pb.MetricsCollection)
    29  	Hash() uint64
    30  	Clone() Target
    31  	Type() TargetType
    32  }
    33  
    34  // TargetType represents the type of a Target, which identifies a metric
    35  // with the name.
    36  //
    37  // A metric is identified by (metric.info.name, metric.info.target_type).
    38  type TargetType struct {
    39  	// Name is the name of the TargeType that can be given to --target-type
    40  	// command line option.
    41  	Name string
    42  	// Type is the reflect.Type of the Target struct.
    43  	Type reflect.Type
    44  }
    45  
    46  func (tt TargetType) String() string {
    47  	return fmt.Sprintf("%s:%s", tt.Name, tt.Type)
    48  }