Add version/correlation headers to Nexus and Praxis ecosystem clients
mavend's hand-rolled Nexus and Praxis HTTP clients sent bare requests with no version or correlation headers, unlike the Hexis client. Added a shared context-based correlation ID mechanism and version headers (X-Nexus-Version, X-Praxis-Version) across all Nexus/Praxis call sites, and threaded the correlation ID already generated in executeCapability through to the Nexus/Praxis calls in the same request chain. Synced vendor/ copy of hexis/pkg/client after its WithCorrelationID addition. Part of Vikunja #273. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ghELqYhZNLub2TXGMazqA
This commit is contained in:
+34
-3
@@ -17,6 +17,30 @@ import (
|
||||
"github.com/kami/maven/internal/config"
|
||||
)
|
||||
|
||||
// ecosystemCorrelationKey carries a per-call correlation ID through context
|
||||
// so every ecosystem client (Nexus, Praxis, Hexis) tags its request with the
|
||||
// same ID, letting a single Maven-initiated action be traced end to end.
|
||||
type ecosystemCorrelationKey struct{}
|
||||
|
||||
func withCorrelationID(ctx context.Context, id string) context.Context {
|
||||
return context.WithValue(ctx, ecosystemCorrelationKey{}, id)
|
||||
}
|
||||
|
||||
func correlationIDFromCtx(ctx context.Context) string {
|
||||
id, _ := ctx.Value(ecosystemCorrelationKey{}).(string)
|
||||
return id
|
||||
}
|
||||
|
||||
// setEcosystemHeaders stamps the version and correlation headers common to
|
||||
// every outgoing ecosystem request.
|
||||
func setEcosystemHeaders(req *http.Request, ctx context.Context, versionHeader string) {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set(versionHeader, "v1")
|
||||
if id := correlationIDFromCtx(ctx); id != "" {
|
||||
req.Header.Set("X-Correlation-ID", id)
|
||||
}
|
||||
}
|
||||
|
||||
type nexusClient struct {
|
||||
baseURL string
|
||||
httpClient *http.Client
|
||||
@@ -83,7 +107,7 @@ func (c *nexusClient) Resolve(ctx context.Context, query string, types []string)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
setEcosystemHeaders(req, ctx, "X-Nexus-Version")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
@@ -108,6 +132,7 @@ func (c *nexusClient) Health(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
setEcosystemHeaders(req, ctx, "X-Nexus-Version")
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -140,6 +165,7 @@ func (c *praxisClient) getJSON(ctx context.Context, path string, out any) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
setEcosystemHeaders(req, ctx, "X-Praxis-Version")
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -191,7 +217,7 @@ func (c *praxisClient) postItemAction(ctx context.Context, path, itemID string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
setEcosystemHeaders(req, ctx, "X-Praxis-Version")
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -232,7 +258,7 @@ func (c *praxisClient) Pin(ctx context.Context, itemID string, pinned bool) (*pr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
setEcosystemHeaders(req, ctx, "X-Praxis-Version")
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -308,6 +334,9 @@ func (w *ecosystemWiring) resolveEntityReference(ctx context.Context, text strin
|
||||
if w == nil || w.nexus == nil {
|
||||
return "", "", nil, nil
|
||||
}
|
||||
if correlationIDFromCtx(ctx) == "" {
|
||||
ctx = withCorrelationID(ctx, newCorrelationID())
|
||||
}
|
||||
result, err := w.nexus.Resolve(ctx, text, entityTypes)
|
||||
if err != nil {
|
||||
log.Printf("ecosystem: nexus resolve error: %v", err)
|
||||
@@ -353,6 +382,8 @@ func (w *ecosystemWiring) executeCapability(ctx context.Context, capabilityID, t
|
||||
return "", fmt.Errorf("hexis not configured")
|
||||
}
|
||||
correlationID = newCorrelationID()
|
||||
ctx = withCorrelationID(ctx, correlationID)
|
||||
ctx = hexisclient.WithCorrelationID(ctx, correlationID)
|
||||
req := hexisclient.ExecuteRequest{
|
||||
CapabilityID: capabilityID,
|
||||
TargetEntityID: targetEntityID,
|
||||
|
||||
Reference in New Issue
Block a user