mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-13 00:58:50 +00:00
feat: improve gateway.yaml path handling and Olric client initialization
- Enhanced the DefaultPath function to remember the preferred data path for gateway.yaml, allowing for better error messaging and fallback options. - Introduced a new function to initialize the Olric client with retry logic, improving resilience during client setup and providing clearer logging for connection attempts. - Updated logging to provide detailed feedback on Olric client initialization attempts, enhancing troubleshooting capabilities.
This commit is contained in:
parent
747be5863b
commit
5d6de3b0b8
15
CHANGELOG.md
15
CHANGELOG.md
@ -13,6 +13,21 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
|
|||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
## [0.69.13] - 2025-11-14
|
||||||
|
|
||||||
|
### Added
|
||||||
|
\n
|
||||||
|
### Changed
|
||||||
|
- The Gateway service now waits for the Olric cache service to start before attempting initialization.
|
||||||
|
- Improved robustness of Olric cache client initialization with retry logic and exponential backoff.
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Corrected the default path logic for 'gateway.yaml' to prioritize the production data directory while maintaining fallback to legacy paths.
|
||||||
|
|
||||||
## [0.69.12] - 2025-11-14
|
## [0.69.12] - 2025-11-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -19,7 +19,7 @@ test-e2e:
|
|||||||
|
|
||||||
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports install-hooks kill
|
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports install-hooks kill
|
||||||
|
|
||||||
VERSION := 0.69.12
|
VERSION := 0.69.13
|
||||||
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
||||||
|
|||||||
@ -42,14 +42,15 @@ func DefaultPath(component string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gatewayDefault string
|
||||||
// For gateway.yaml, check data/ directory first (production location)
|
// For gateway.yaml, check data/ directory first (production location)
|
||||||
if component == "gateway.yaml" {
|
if component == "gateway.yaml" {
|
||||||
dataPath := filepath.Join(dir, "data", component)
|
dataPath := filepath.Join(dir, "data", component)
|
||||||
if _, err := os.Stat(dataPath); err == nil {
|
if _, err := os.Stat(dataPath); err == nil {
|
||||||
return dataPath, nil
|
return dataPath, nil
|
||||||
}
|
}
|
||||||
// Return data path as default for gateway.yaml (even if it doesn't exist yet)
|
// Remember the preferred default so we can still fall back to legacy paths
|
||||||
return dataPath, nil
|
gatewayDefault = dataPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// First check in ~/.debros/configs/ (production installer location)
|
// First check in ~/.debros/configs/ (production installer location)
|
||||||
@ -64,6 +65,12 @@ func DefaultPath(component string) (string, error) {
|
|||||||
return legacyPath, nil
|
return legacyPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gatewayDefault != "" {
|
||||||
|
// If we preferred the data path (gateway.yaml) but didn't find it anywhere else,
|
||||||
|
// return the data path so error messages point to the production location.
|
||||||
|
return gatewayDefault, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Return configs path as default (even if it doesn't exist yet)
|
// Return configs path as default (even if it doesn't exist yet)
|
||||||
// This allows the error message to show the expected production location
|
// This allows the error message to show the expected production location
|
||||||
return configsPath, nil
|
return configsPath, nil
|
||||||
|
|||||||
@ -233,11 +233,12 @@ WantedBy=multi-user.target
|
|||||||
// GenerateGatewayService generates the DeBros Gateway systemd unit
|
// GenerateGatewayService generates the DeBros Gateway systemd unit
|
||||||
func (ssg *SystemdServiceGenerator) GenerateGatewayService(nodeType string) string {
|
func (ssg *SystemdServiceGenerator) GenerateGatewayService(nodeType string) string {
|
||||||
nodeService := fmt.Sprintf("debros-node-%s.service", nodeType)
|
nodeService := fmt.Sprintf("debros-node-%s.service", nodeType)
|
||||||
|
olricService := "debros-olric.service"
|
||||||
logFile := filepath.Join(ssg.debrosDir, "logs", "gateway.log")
|
logFile := filepath.Join(ssg.debrosDir, "logs", "gateway.log")
|
||||||
return fmt.Sprintf(`[Unit]
|
return fmt.Sprintf(`[Unit]
|
||||||
Description=DeBros Gateway
|
Description=DeBros Gateway
|
||||||
After=%s
|
After=%s %s
|
||||||
Wants=%s
|
Wants=%s %s
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
@ -262,7 +263,7 @@ ReadWritePaths=%s
|
|||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
`, nodeService, nodeService, ssg.debrosHome, ssg.debrosHome, ssg.debrosHome, ssg.debrosDir, logFile, logFile, ssg.debrosDir)
|
`, nodeService, olricService, nodeService, olricService, ssg.debrosHome, ssg.debrosHome, ssg.debrosHome, ssg.debrosDir, logFile, logFile, ssg.debrosDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemdController manages systemd service operations
|
// SystemdController manages systemd service operations
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -25,6 +26,12 @@ import (
|
|||||||
_ "github.com/rqlite/gorqlite/stdlib"
|
_ "github.com/rqlite/gorqlite/stdlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
olricInitMaxAttempts = 5
|
||||||
|
olricInitInitialBackoff = 500 * time.Millisecond
|
||||||
|
olricInitMaxBackoff = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// Config holds configuration for the gateway server
|
// Config holds configuration for the gateway server
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
@ -182,7 +189,7 @@ func New(logger *logging.ColoredLogger, cfg *Config) (*Gateway, error) {
|
|||||||
Servers: olricServers,
|
Servers: olricServers,
|
||||||
Timeout: cfg.OlricTimeout,
|
Timeout: cfg.OlricTimeout,
|
||||||
}
|
}
|
||||||
olricClient, olricErr := olric.NewClient(olricCfg, logger.Logger)
|
olricClient, olricErr := initializeOlricClientWithRetry(olricCfg, logger)
|
||||||
if olricErr != nil {
|
if olricErr != nil {
|
||||||
logger.ComponentWarn(logging.ComponentGeneral, "failed to initialize Olric cache client; cache endpoints disabled", zap.Error(olricErr))
|
logger.ComponentWarn(logging.ComponentGeneral, "failed to initialize Olric cache client; cache endpoints disabled", zap.Error(olricErr))
|
||||||
} else {
|
} else {
|
||||||
@ -330,6 +337,38 @@ func (g *Gateway) getLocalSubscribers(topic, namespace string) []*localSubscribe
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initializeOlricClientWithRetry(cfg olric.Config, logger *logging.ColoredLogger) (*olric.Client, error) {
|
||||||
|
backoff := olricInitInitialBackoff
|
||||||
|
|
||||||
|
for attempt := 1; attempt <= olricInitMaxAttempts; attempt++ {
|
||||||
|
client, err := olric.NewClient(cfg, logger.Logger)
|
||||||
|
if err == nil {
|
||||||
|
if attempt > 1 {
|
||||||
|
logger.ComponentInfo(logging.ComponentGeneral, "Olric cache client initialized after retries",
|
||||||
|
zap.Int("attempts", attempt))
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.ComponentWarn(logging.ComponentGeneral, "Olric cache client init attempt failed",
|
||||||
|
zap.Int("attempt", attempt),
|
||||||
|
zap.Duration("retry_in", backoff),
|
||||||
|
zap.Error(err))
|
||||||
|
|
||||||
|
if attempt == olricInitMaxAttempts {
|
||||||
|
return nil, fmt.Errorf("failed to initialize Olric cache client after %d attempts: %w", attempt, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(backoff)
|
||||||
|
backoff *= 2
|
||||||
|
if backoff > olricInitMaxBackoff {
|
||||||
|
backoff = olricInitMaxBackoff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("failed to initialize Olric cache client")
|
||||||
|
}
|
||||||
|
|
||||||
// discoverOlricServers discovers Olric server addresses from LibP2P peers
|
// discoverOlricServers discovers Olric server addresses from LibP2P peers
|
||||||
// Returns a list of IP:port addresses where Olric servers are expected to run (port 3320)
|
// Returns a list of IP:port addresses where Olric servers are expected to run (port 3320)
|
||||||
func discoverOlricServers(networkClient client.NetworkClient, logger *zap.Logger) []string {
|
func discoverOlricServers(networkClient client.NetworkClient, logger *zap.Logger) []string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user