Files
o11y/cmd/community/server.go
zeekayandHanzo Dev 212410de59 The warehouse is reached as an IAM identity, never a password
A telemetry store now presents an IAM access token minted for the
datastore audience at every handshake, and has no other credential to
present. The token is the embedding process's identity, set by the host
rather than read from configuration: the standalone server mints its own
from IAM_CLIENT_ID and IAM_CLIENT_SECRET, and cloud hands the embed the
identity its o11y app already holds.

A DSN now says where the warehouse is and nothing else. One that names a
user or password is refused, and a store with no identity is not built.
Pooled connections live five minutes, so each replacement presents a
current token and a revoked identity keeps nothing for long.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-24 14:35:36 -07:00

82 lines
2.2 KiB
Go

package main
import (
"context"
"log/slog"
"github.com/spf13/cobra"
"github.com/hanzoai/o11y/cmd"
"github.com/hanzoai/o11y/pkg/community"
"github.com/hanzoai/o11y/pkg/errors"
"github.com/hanzoai/o11y/pkg/o11y"
"github.com/hanzoai/o11y/pkg/version"
)
func registerServer(parentCmd *cobra.Command, logger *slog.Logger) {
var configFiles []string
serverCmd := &cobra.Command{
Use: "server",
Short: "Run the O11y server",
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
RunE: func(currCmd *cobra.Command, args []string) error {
config, err := cmd.NewO11yConfig(currCmd.Context(), logger, configFiles)
if err != nil {
return err
}
return runServer(currCmd.Context(), config, logger)
},
}
serverCmd.Flags().StringArrayVar(&configFiles, "config", nil, "path to a YAML configuration file (can be specified multiple times, later files override earlier ones)")
parentCmd.AddCommand(serverCmd)
}
func runServer(ctx context.Context, config o11y.Config, logger *slog.Logger) error {
// print the version
version.Info.PrettyPrint(config.Version)
token, err := identity()
if err != nil {
logger.ErrorContext(ctx, "failed to create o11y server", errors.Attr(err))
return err
}
config.TelemetryStore.Datastore.Token = token
// community.NewServer is the ONE construction shared with the hanzoai/cloud
// embed — same providers, same identity (iamidentn gateway-header auth), same
// wiring. Standalone owns the process: bind listeners, run background
// evaluation, block until shutdown.
server, o11y, err := community.NewServer(ctx, config)
if err != nil {
logger.ErrorContext(ctx, "failed to create o11y server", errors.Attr(err))
return err
}
if err := server.Start(ctx); err != nil {
logger.ErrorContext(ctx, "failed to start server", errors.Attr(err))
return err
}
o11y.Start(ctx)
if err := o11y.Wait(ctx); err != nil {
logger.ErrorContext(ctx, "failed to start o11y", errors.Attr(err))
return err
}
if err := server.Stop(ctx); err != nil {
logger.ErrorContext(ctx, "failed to stop server", errors.Attr(err))
return err
}
if err := o11y.Stop(ctx); err != nil {
logger.ErrorContext(ctx, "failed to stop o11y", errors.Attr(err))
return err
}
return nil
}