github.com/grafana/pyroscope@v1.18.0/pkg/metastore/admin/pages.go (about)

     1  package admin
     2  
     3  import (
     4  	_ "embed"
     5  	"html/template"
     6  	"time"
     7  
     8  	"github.com/grafana/pyroscope/pkg/metastore/discovery"
     9  )
    10  
    11  //go:embed metastore.nodes.gohtml
    12  var nodesPageHtml string
    13  
    14  //go:embed metastore.client.gohtml
    15  var clientTestPageHtml string
    16  
    17  type metastoreNode struct {
    18  	// from Discovery
    19  	DiscoveryServerId string
    20  	RaftServerId      string
    21  	ResolvedAddress   string
    22  
    23  	// from Raft
    24  	Member        bool
    25  	State         string
    26  	CommitIndex   uint64
    27  	AppliedIndex  uint64
    28  	LastIndex     uint64
    29  	LeaderId      string
    30  	ConfigIndex   uint64
    31  	NumPeers      int
    32  	CurrentTerm   uint64
    33  	BuildVersion  string
    34  	BuildRevision string
    35  	Stats         map[string]string
    36  }
    37  
    38  type raftNodeState struct {
    39  	Nodes           []*metastoreNode
    40  	ObservedLeaders map[string]int
    41  	CurrentTerm     uint64
    42  	NumNodes        int
    43  }
    44  
    45  type nodesPageContent struct {
    46  	DiscoveredServers []discovery.Server
    47  	Raft              *raftNodeState
    48  	Now               time.Time
    49  }
    50  
    51  type clientTestPageContent struct {
    52  	Raft             *raftNodeState
    53  	Now              time.Time
    54  	TestResponse     string
    55  	TestResponseTime time.Duration
    56  }
    57  
    58  type templates struct {
    59  	nodesTemplate      *template.Template
    60  	clientTestTemplate *template.Template
    61  }
    62  
    63  var pageTemplates = initTemplates()
    64  
    65  func initTemplates() *templates {
    66  	nodesTemplate := template.New("nodes")
    67  	template.Must(nodesTemplate.Parse(nodesPageHtml))
    68  	clientTestTemplate := template.New("clientTest")
    69  	template.Must(clientTestTemplate.Parse(clientTestPageHtml))
    70  	t := &templates{
    71  		nodesTemplate:      nodesTemplate,
    72  		clientTestTemplate: clientTestTemplate,
    73  	}
    74  	return t
    75  }