Compare commits
	
		
			5 Commits
		
	
	
		
			v0.3.1
			...
			87344dd601
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 87344dd601 | |||
| 39e6611602 | |||
| 355d246010 | |||
| e5836a8b97 | |||
| f6d160a7f8 | 
							
								
								
									
										18
									
								
								config/depenv/context.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								config/depenv/context.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
package depenv
 | 
			
		||||
 | 
			
		||||
import "context"
 | 
			
		||||
 | 
			
		||||
type contextKey struct{}
 | 
			
		||||
 | 
			
		||||
// NewContext adds the deployment environment to the context
 | 
			
		||||
func NewContext(ctx context.Context, d DeploymentEnvironment) context.Context {
 | 
			
		||||
	return context.WithValue(ctx, contextKey{}, d)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FromContext retrieves the deployment environment from the context
 | 
			
		||||
func FromContext(ctx context.Context) DeploymentEnvironment {
 | 
			
		||||
	if d, ok := ctx.Value(contextKey{}).(DeploymentEnvironment); ok {
 | 
			
		||||
		return d
 | 
			
		||||
	}
 | 
			
		||||
	return DeployUndefined
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										83
									
								
								config/depenv/depenv.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								config/depenv/depenv.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
			
		||||
package depenv
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var manageServers = map[DeploymentEnvironment]string{
 | 
			
		||||
	DeployDevel: "https://manage.askdev.grundclock.com",
 | 
			
		||||
	DeployTest:  "https://manage.beta.grundclock.com",
 | 
			
		||||
	DeployProd:  "https://manage.ntppool.org",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var apiServers = map[DeploymentEnvironment]string{
 | 
			
		||||
	DeployDevel: "https://dev-api.ntppool.dev",
 | 
			
		||||
	DeployTest:  "https://beta-api.ntppool.dev",
 | 
			
		||||
	DeployProd:  "https://api.ntppool.dev",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// var validationServers = map[DeploymentEnvironment]string{
 | 
			
		||||
// 	DeployDevel: "https://v.ntp.dev/d/",
 | 
			
		||||
// 	DeployTest:  "https://v.ntp.dev/b/",
 | 
			
		||||
// 	DeployProd:  "https://v.ntp.dev/p/",
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	DeployUndefined DeploymentEnvironment = iota
 | 
			
		||||
	DeployDevel
 | 
			
		||||
	DeployTest
 | 
			
		||||
	DeployProd
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DeploymentEnvironment uint8
 | 
			
		||||
 | 
			
		||||
func DeploymentEnvironmentFromString(s string) DeploymentEnvironment {
 | 
			
		||||
	switch s {
 | 
			
		||||
	case "devel", "dev":
 | 
			
		||||
		return DeployDevel
 | 
			
		||||
	case "test", "beta":
 | 
			
		||||
		return DeployTest
 | 
			
		||||
	case "prod":
 | 
			
		||||
		return DeployProd
 | 
			
		||||
	default:
 | 
			
		||||
		return DeployUndefined
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d DeploymentEnvironment) String() string {
 | 
			
		||||
	switch d {
 | 
			
		||||
	case DeployProd:
 | 
			
		||||
		return "prod"
 | 
			
		||||
	case DeployTest:
 | 
			
		||||
		return "test"
 | 
			
		||||
	case DeployDevel:
 | 
			
		||||
		return "devel"
 | 
			
		||||
	default:
 | 
			
		||||
		panic("invalid DeploymentEnvironment")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d DeploymentEnvironment) APIHost() string {
 | 
			
		||||
	if apiHost := os.Getenv("API_HOST"); apiHost != "" {
 | 
			
		||||
		return apiHost
 | 
			
		||||
	}
 | 
			
		||||
	return apiServers[d]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d DeploymentEnvironment) ManageURL(path string) string {
 | 
			
		||||
	return manageServers[d] + path
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DeploymentEnvironment) UnmarshalText(text []byte) error {
 | 
			
		||||
	s := string(text)
 | 
			
		||||
	if s == "" {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	env := DeploymentEnvironmentFromString(s)
 | 
			
		||||
	if env == DeployUndefined {
 | 
			
		||||
		return fmt.Errorf("invalid deployment environment: %s", s)
 | 
			
		||||
	}
 | 
			
		||||
	*d = env
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										40
									
								
								config/depenv/monitor_names.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								config/depenv/monitor_names.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
package depenv
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var monitorApiServers = map[DeploymentEnvironment]string{
 | 
			
		||||
	DeployDevel: "https://api.devel.mon.ntppool.dev",
 | 
			
		||||
	DeployTest:  "https://api.test.mon.ntppool.dev",
 | 
			
		||||
	DeployProd:  "https://api.mon.ntppool.dev",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d DeploymentEnvironment) MonitorAPIHost() string {
 | 
			
		||||
	return monitorApiServers[d]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDeploymentEnvironmentFromName(clientName string) (DeploymentEnvironment, error) {
 | 
			
		||||
	clientName = strings.ToLower(clientName)
 | 
			
		||||
 | 
			
		||||
	if !strings.HasSuffix(clientName, ".mon.ntppool.dev") {
 | 
			
		||||
		return DeployUndefined, fmt.Errorf("invalid client name %s", clientName)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if clientName == "api.mon.ntppool.dev" {
 | 
			
		||||
		return DeployProd, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prefix := clientName[:strings.Index(clientName, ".mon.ntppool.dev")]
 | 
			
		||||
	parts := strings.Split(prefix, ".")
 | 
			
		||||
	if len(parts) != 2 {
 | 
			
		||||
		return DeployUndefined, fmt.Errorf("invalid client name %s", clientName)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if d := DeploymentEnvironmentFromString(parts[1]); d != DeployUndefined {
 | 
			
		||||
		return d, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return DeployUndefined, fmt.Errorf("invalid client name %s (unknown environment %s)", clientName, parts[1])
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										4
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,8 +1,6 @@
 | 
			
		||||
module go.ntppool.org/common
 | 
			
		||||
 | 
			
		||||
go 1.23
 | 
			
		||||
 | 
			
		||||
toolchain go1.23.4
 | 
			
		||||
go 1.23.5
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/abh/certman v0.4.0
 | 
			
		||||
 
 | 
			
		||||
@@ -59,11 +59,10 @@ func (srv *Server) Listen(ctx context.Context, port int) error {
 | 
			
		||||
 | 
			
		||||
	<-ctx.Done()
 | 
			
		||||
 | 
			
		||||
	ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	g.Go(func() error {
 | 
			
		||||
		if err := hsrv.Shutdown(ctx); err != nil {
 | 
			
		||||
		shCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
 | 
			
		||||
		defer cancel()
 | 
			
		||||
		if err := hsrv.Shutdown(shCtx); err != nil {
 | 
			
		||||
			srv.log.Error("health check server shutdown failed", "err", err)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
 | 
			
		||||
go install github.com/goreleaser/goreleaser/v2@v2.5.0
 | 
			
		||||
go install github.com/goreleaser/goreleaser/v2@v2.8.2
 | 
			
		||||
 | 
			
		||||
if [ ! -z "${harbor_username:-}" ]; then
 | 
			
		||||
  DOCKER_FILE=~/.docker/config.json
 | 
			
		||||
 
 | 
			
		||||
@@ -196,7 +196,6 @@ func SetupSDK(ctx context.Context, cfg *TracerConfig) (shutdown TpShutdownFunc,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newOLTPExporter(ctx context.Context, cfg *TracerConfig) (sdktrace.SpanExporter, error) {
 | 
			
		||||
 | 
			
		||||
	log := logger.Setup()
 | 
			
		||||
 | 
			
		||||
	var tlsConfig *tls.Config
 | 
			
		||||
 
 | 
			
		||||
@@ -13,10 +13,12 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// VERSION has the current software version (set in the build process)
 | 
			
		||||
var VERSION string
 | 
			
		||||
var buildTime string
 | 
			
		||||
var gitVersion string
 | 
			
		||||
var gitModified bool
 | 
			
		||||
var (
 | 
			
		||||
	VERSION     string
 | 
			
		||||
	buildTime   string
 | 
			
		||||
	gitVersion  string
 | 
			
		||||
	gitModified bool
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var info Info
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +30,6 @@ type Info struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
 | 
			
		||||
	info.BuildTime = buildTime
 | 
			
		||||
	info.GitRev = gitVersion
 | 
			
		||||
 | 
			
		||||
@@ -90,6 +91,15 @@ func VersionCmd(name string) *cobra.Command {
 | 
			
		||||
	return versionCmd
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type KongVersionCmd struct {
 | 
			
		||||
	Name string `kong:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (cmd *KongVersionCmd) Run() error {
 | 
			
		||||
	fmt.Printf("%s %s\n", cmd.Name, Version())
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RegisterMetric(name string, registry prometheus.Registerer) {
 | 
			
		||||
	if len(name) > 0 {
 | 
			
		||||
		name = strings.ReplaceAll(name, "-", "_")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user