Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeldonIO Seldon core Hodometer Publish

From Leeroopedia
Knowledge Sources
Domains Observability, Metrics_Publishing, Usage_Telemetry
Last Updated 2026-02-13 14:00 GMT

Overview

Concrete tool for publishing collected usage metrics to remote endpoints via the Mixpanel event tracking API provided by the Hodometer package.

Description

The JsonPublisher struct implements the Publisher interface and sends collected UsageMetrics to one or more remote URLs using the Mixpanel client library. It flattens the metrics struct into key-value properties using reflection, adds a unique insert ID and timestamp, and publishes concurrently to all configured endpoints. The HTTP client uses retryable-http with exponential backoff (up to 20 retries, 1-30 second wait range) for resilience.

The flattenStructToProperties helper recursively walks the UsageMetrics struct (including embedded structs) and extracts JSON-tagged fields into a flat property map for the Mixpanel event payload.

Usage

Use this publisher as the output stage of the Hodometer metrics pipeline. After the SeldonCoreCollector gathers metrics, the publisher sends them to the configured analytics endpoints.

Code Reference

Source Location

Signature

type Publisher interface {
    Publish(ctx context.Context, metrics *UsageMetrics) error
}

type JsonPublisher struct {
    clients []urlAndClient
    logger  logrus.FieldLogger
    apiUrl  string
}

func NewJsonPublisher(
    logger logrus.FieldLogger,
    publishUrls []*url.URL,
) (*JsonPublisher, error)

func (jp *JsonPublisher) Publish(
    ctx context.Context,
    metrics *UsageMetrics,
) error

Import

import "github.com/seldonio/seldon-core/hodometer/pkg/hodometer"

I/O Contract

Inputs

Name Type Required Description
logger logrus.FieldLogger Yes Structured logger for operational output
publishUrls []*url.URL Yes One or more target URLs to publish metrics to (must not be empty)
ctx context.Context Yes Context for cancellation
metrics *UsageMetrics Yes The collected usage metrics to publish

Outputs

Name Type Description
error error Returned by NewJsonPublisher if no URLs provided; Publish always returns nil (errors logged)
HTTP POST Mixpanel event Metrics published as Mixpanel Track event to each configured URL

Usage Examples

Creating and Using a Publisher

package main

import (
    "context"
    "net/url"
    "github.com/sirupsen/logrus"
    "github.com/seldonio/seldon-core/hodometer/pkg/hodometer"
)

func main() {
    logger := logrus.New()

    targetUrl, _ := url.Parse("https://metrics.seldon.io/collect")
    publisher, err := hodometer.NewJsonPublisher(
        logger,
        []*url.URL{targetUrl},
    )
    if err != nil {
        logger.Fatalf("failed to create publisher: %v", err)
    }

    // Publish collected metrics
    metrics := &hodometer.UsageMetrics{}
    metrics.ClusterId = "abc-123"
    metrics.ModelCount = 5

    err = publisher.Publish(context.Background(), metrics)
    if err != nil {
        logger.Errorf("publish failed: %v", err)
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment