mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 00:40:25 +02:00
report instance hostname (#2175)
This commit is contained in:
parent
0071b4e7a5
commit
cbaf33032d
1 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
envoy_service_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
|
||||
|
@ -43,6 +44,8 @@ type Manager struct {
|
|||
resources map[string][]*envoy_service_discovery_v3.Resource
|
||||
|
||||
nonceToConfig *lru.Cache
|
||||
|
||||
hostname string
|
||||
}
|
||||
|
||||
// NewManager creates a new Manager.
|
||||
|
@ -56,6 +59,8 @@ func NewManager(resources map[string][]*envoy_service_discovery_v3.Resource, eve
|
|||
nonceToConfig: nonceToConfig,
|
||||
nonce: uuid.NewString(),
|
||||
resources: resources,
|
||||
|
||||
hostname: getHostname(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +271,7 @@ func (mgr *Manager) nonceToConfigVersion(nonce string) (ver uint64) {
|
|||
|
||||
func (mgr *Manager) nackEvent(ctx context.Context, req *envoy_service_discovery_v3.DeltaDiscoveryRequest) {
|
||||
mgr.eventHandler(&events.EnvoyConfigurationEvent{
|
||||
Instance: mgr.hostname,
|
||||
Kind: events.EnvoyConfigurationEvent_EVENT_DISCOVERY_REQUEST,
|
||||
Time: timestamppb.Now(),
|
||||
Message: req.ErrorDetail.Message,
|
||||
|
@ -290,6 +296,7 @@ func (mgr *Manager) nackEvent(ctx context.Context, req *envoy_service_discovery_
|
|||
|
||||
func (mgr *Manager) ackEvent(ctx context.Context, req *envoy_service_discovery_v3.DeltaDiscoveryRequest) {
|
||||
mgr.eventHandler(&events.EnvoyConfigurationEvent{
|
||||
Instance: mgr.hostname,
|
||||
Kind: events.EnvoyConfigurationEvent_EVENT_DISCOVERY_REQUEST,
|
||||
Time: timestamppb.Now(),
|
||||
ConfigVersion: mgr.nonceToConfigVersion(req.ResponseNonce),
|
||||
|
@ -309,6 +316,7 @@ func (mgr *Manager) ackEvent(ctx context.Context, req *envoy_service_discovery_v
|
|||
|
||||
func (mgr *Manager) changeEvent(ctx context.Context, res *envoy_service_discovery_v3.DeltaDiscoveryResponse) {
|
||||
mgr.eventHandler(&events.EnvoyConfigurationEvent{
|
||||
Instance: mgr.hostname,
|
||||
Kind: events.EnvoyConfigurationEvent_EVENT_DISCOVERY_RESPONSE,
|
||||
Time: timestamppb.Now(),
|
||||
ConfigVersion: mgr.nonceToConfigVersion(res.Nonce),
|
||||
|
@ -333,3 +341,14 @@ func resourceNames(res []*envoy_service_discovery_v3.Resource) []string {
|
|||
}
|
||||
return txt
|
||||
}
|
||||
|
||||
func getHostname() string {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = os.Getenv("HOSTNAME")
|
||||
}
|
||||
if hostname == "" {
|
||||
hostname = "__unknown__"
|
||||
}
|
||||
return hostname
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue