func NewLease(c client.LeaseClient, cluster, potentialLeader string, minT, maxT, currentTime time.Time) (*Lease, error) {
	stateFromDB, err := c.UpdateLease(context.Background(), cluster, potentialLeader, minT, maxT)
	if err != nil {
		return nil, fmt.Errorf("could not create new lease: %#v", err)
	}
	exposeHAStateToMetrics(cluster, "", stateFromDB.Leader)
	return &Lease{
		client:                c,
		state:                 stateFromDB,
		MaxTimeSeen:           maxT,
		MaxTimeInstance:       potentialLeader,
		MaxTimeSeenLeader:     maxT,
		RecentLeaderWriteTime: currentTime,
	}, nil
}
Creates a new Lease and immediately synchronizes with the database, it either
- sets the potentialLeader as the leader for the cluster with a lease
for the requested minT and maxT
- or the existing leader and lease details are returned and set in the
new Lease.
An error is returned if an error occurred querying the database.
package state
import (
	"context"
	"fmt"
	"sync"
	"time"
	"github.com/timescale/promscale/pkg/ha/client"
	"github.com/timescale/promscale/pkg/pgmodel/metrics"
)
const (
	haLastWriteInterval = 30 * time.Second
)
type Lease struct {
	_mu                   sync.RWMutex
	state                 client.LeaseDBState
	MaxTimeSeen           time.Time  
	MaxTimeInstance       string     
	MaxTimeSeenLeader     time.Time  
	RecentLeaderWriteTime time.Time  
	client client.LeaseClient
}