github.com/cilium/cilium@v1.16.2/pkg/hive/health/cell.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package health
     5  
     6  import (
     7  	"github.com/cilium/hive/cell"
     8  
     9  	"github.com/cilium/statedb"
    10  	"github.com/cilium/statedb/index"
    11  
    12  	"github.com/cilium/cilium/pkg/hive/health/types"
    13  	"github.com/cilium/cilium/pkg/metrics"
    14  )
    15  
    16  var Cell = cell.Module(
    17  	"health",
    18  	"Modular Health Provider V2",
    19  	cell.ProvidePrivate(newTablesPrivate),
    20  	cell.Provide(
    21  		newHealthV2Provider,
    22  		statedb.RWTable[types.Status].ToTable,
    23  	),
    24  
    25  	// Module health metrics.
    26  	cell.Invoke(metricPublisher),
    27  	metrics.Metric(newMetrics),
    28  )
    29  
    30  var (
    31  	PrimaryIndex = statedb.Index[types.Status, types.HealthID]{
    32  		Name: "identifier",
    33  		FromObject: func(s types.Status) index.KeySet {
    34  			return index.NewKeySet([]byte(s.ID.String()))
    35  		},
    36  		FromKey: func(k types.HealthID) index.Key {
    37  			return index.Key([]byte(k))
    38  		},
    39  		Unique: true,
    40  	}
    41  	LevelIndex = statedb.Index[types.Status, types.Level]{
    42  		Name: "level",
    43  		FromObject: func(s types.Status) index.KeySet {
    44  			return index.NewKeySet([]byte(s.Level))
    45  		},
    46  		FromKey: func(key types.Level) index.Key {
    47  			return index.Key([]byte(key))
    48  		},
    49  		Unique: false,
    50  	}
    51  )
    52  
    53  func newTablesPrivate(db *statedb.DB) (statedb.RWTable[types.Status], error) {
    54  	statusTable, err := statedb.NewTable(TableName,
    55  		PrimaryIndex,
    56  		LevelIndex)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	if err := db.RegisterTable(statusTable); err != nil {
    61  		return nil, err
    62  	}
    63  	return statusTable, nil
    64  }