github.com/kiali/kiali@v1.84.0/tracing/jaeger/model/process.go (about)

     1  // Copyright (c) 2019 The Jaeger Authors.
     2  // Copyright (c) 2017 Uber Technologies, Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  // http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package model
    17  
    18  import (
    19  	"io"
    20  )
    21  
    22  // NewProcess creates a new Process for given serviceName and tags.
    23  // The tags are sorted in place and kept in the same array/slice,
    24  // in order to store the Process in a canonical form that is relied
    25  // upon by the Equal and Hash functions.
    26  func NewProcess(serviceName string, tags []*KeyValue) *Process {
    27  	typedTags := KeyValues(tags)
    28  	typedTags.Sort()
    29  	return &Process{ServiceName: serviceName, Tags: typedTags}
    30  }
    31  
    32  // Equal compares Process object with another Process.
    33  func (p *Process) Equal(other *Process) bool {
    34  	if p.ServiceName != other.ServiceName {
    35  		return false
    36  	}
    37  	return KeyValues(p.Tags).Equal(other.Tags)
    38  }
    39  
    40  // Hash implements Hash from Hashable.
    41  func (p *Process) Hash(w io.Writer) (err error) {
    42  	if _, err := w.Write([]byte(p.ServiceName)); err != nil {
    43  		return err
    44  	}
    45  	return KeyValues(p.Tags).Hash(w)
    46  }