chipingress

package module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 18 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ChipIngress

ChipIngress is a gRPC client library for interacting with the ChipIngress service. It provides functionality for publishing CloudEvents to the ChipIngress service and supports various authentication methods.

Features

  • CloudEvent Publishing: Publish single events or batches of events
  • Authentication Support: Multiple authentication methods including basic auth and token-based auth
  • Secure Communication: Support for both TLS and insecure connections
  • Event Management: Utilities for creating, converting, and managing CloudEvents
  • OpenTelemetry Integration: Built-in OpenTelemetry support for distributed tracing and metrics

Installation

go get github.com/smartcontractkit/chainlink-common/pkg/chipingress

Usage

Basic Client Creation
import "github.com/smartcontractkit/chainlink-common/pkg/chipingress"

// Create client with default settings (insecure connection)
client, err := chipingress.NewClient("localhost:9090")
if err != nil {
    log.Fatal(err)
}
defer client.Close()
Client with TLS
client, err := chipingress.NewClient("example.com:9090", chipingress.WithTLS())
if err != nil {
    log.Fatal(err)
}
defer client.Close()
Client with Authentication
// Basic Auth
client, err := chipingress.NewClient("example.com:9090", 
    chipingress.WithTLS(),
    chipingress.WithBasicAuth("username", "password"))

// Token Auth
tokenProvider := &myTokenProvider{}
client, err := chipingress.NewClient("example.com:9090", 
    chipingress.WithTLS(),
    chipingress.WithTokenAuth(tokenProvider))
Creating and Publishing Events
// Create a new event
event, err := chipingress.NewEvent(
    "my-domain", 
    "my-entity", 
    []byte("event payload"),
    map[string]any{
        "subject": "test-subject",
        "time": time.Now(),
    })
if err != nil {
    log.Fatal(err)
}

// Convert to protobuf
eventPb, err := chipingress.EventToProto(event)
if err != nil {
    log.Fatal(err)
}

// Publish the event
response, err := client.Publish(context.Background(), eventPb)
if err != nil {
    log.Fatal(err)
}
OpenTelemetry Integration

The client automatically instruments gRPC calls with OpenTelemetry for distributed tracing and metrics.

Using Global Providers

By default, the client uses the global OpenTelemetry providers:

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/sdk/trace"
)

// Set up your OpenTelemetry tracer provider
tp := trace.NewTracerProvider(...)
otel.SetTracerProvider(tp)

// Create client - it will automatically use the global tracer
client, err := chipingress.NewClient("example.com:9090", chipingress.WithTLS())
Using Custom Providers

You can also pass custom MeterProvider and TracerProvider instances to the client:

import (
    "go.opentelemetry.io/otel/metric"
    "go.opentelemetry.io/otel/sdk/metric"
    "go.opentelemetry.io/otel/sdk/trace"
    "go.opentelemetry.io/otel/trace"
)

// Create custom providers
meterProvider := metric.NewMeterProvider(...)
tracerProvider := trace.NewTracerProvider(...)

// Create client with custom providers
client, err := chipingress.NewClient("example.com:9090",
    chipingress.WithTLS(),
    chipingress.WithMeterProvider(meterProvider),
    chipingress.WithTracerProvider(tracerProvider))

The client uses otelgrpc.NewClientHandler() to automatically create spans for all gRPC calls, including metrics for request duration, message sizes, and error rates.

Dependencies

  • github.com/cloudevents/sdk-go/v2 - CloudEvents SDK
  • github.com/google/uuid - UUID generation
  • google.golang.org/grpc - gRPC communication
  • google.golang.org/protobuf - Protocol buffer support
  • go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc - OpenTelemetry gRPC instrumentation

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChipIngressClient

type ChipIngressClient = pb.ChipIngressClient

Client

type ChipIngress_StreamEventsClient

type ChipIngress_StreamEventsClient = pb.ChipIngress_StreamEventsClient

type Client

type Client interface {
	pb.ChipIngressClient
	Close() error
	RegisterSchemas(ctx context.Context, schemas ...*pb.Schema) (map[string]int, error)
}

func NewClient

func NewClient(address string, opts ...Opt) (Client, error)

NewClient creates a new client for the Chip Ingress service with optional configuration.

type CloudEvent

type CloudEvent = ce.Event

Cloudevents types

func NewEvent

func NewEvent(domain, entity string, payload []byte, attributes map[string]any) (CloudEvent, error)

NewEvent creates a new CloudEvent with the specified domain, entity, payload, and optional attributes.

func ProtoToEvent

func ProtoToEvent(eventPb *CloudEventPb) (CloudEvent, error)

type CloudEventBatch

type CloudEventBatch = pb.CloudEventBatch

Message types

func EventsToBatch

func EventsToBatch(events []CloudEvent) (*CloudEventBatch, error)

type CloudEventPb

type CloudEventPb = cepb.CloudEvent

func EventToProto

func EventToProto(event CloudEvent) (*CloudEventPb, error)

type EmptyRequest

type EmptyRequest = pb.EmptyRequest

type HeaderProvider

type HeaderProvider interface {
	Headers(ctx context.Context) (map[string]string, error)
}

type NoopClient added in v0.0.10

type NoopClient struct{}

NoopClient is a no-op implementation of the Client interface. All methods return successfully without performing any actual operations.

func (NoopClient) Close added in v0.0.10

func (NoopClient) Close() error

Close is a no-op

func (NoopClient) Ping added in v0.0.10

Ping is a no-op

func (NoopClient) Publish added in v0.0.10

Publish is a no-op

func (NoopClient) PublishBatch added in v0.0.10

func (NoopClient) PublishBatch(ctx context.Context, in *pb.CloudEventBatch, opts ...grpc.CallOption) (*pb.PublishResponse, error)

PublishBatch is a no-op

func (NoopClient) RegisterSchema added in v0.0.10

RegisterSchema is a no-op

func (NoopClient) RegisterSchemas added in v0.0.10

func (NoopClient) RegisterSchemas(ctx context.Context, schemas ...*pb.Schema) (map[string]int, error)

RegisterSchemas is a no-op

func (NoopClient) StreamEvents added in v0.0.10

StreamEvents is a no-op

type Opt

type Opt func(*clientConfig)

Opt defines a function type for configuring the ChipIngressClient.

func WithBasicAuth

func WithBasicAuth(user, pass string) Opt

WithBasicAuth sets the basic-auth credentials for the ChipIngress service. Default is to require TLS for security.

func WithHeaderProvider

func WithHeaderProvider(provider HeaderProvider) Opt

WithHeaderProvider sets a dynamic header provider for requests NOTE: for CSA-Key based authentication, use WithTokenAuth instead.

func WithInsecureConnection

func WithInsecureConnection() Opt

WithInsecureConnection configures the client to use an insecure connection (no TLS).

func WithMeterProvider added in v0.0.8

func WithMeterProvider(provider metric.MeterProvider) Opt

WithMeterProvider sets a custom OpenTelemetry MeterProvider for metrics collection. If not set, the global meter provider will be used.

func WithTLS

func WithTLS() Opt

Add a new option function for TLS with HTTP/2

func WithTokenAuth

func WithTokenAuth(tokenProvider HeaderProvider) Opt

WithTokenAuth sets the token-based credentials for the ChipIngress service. Use for CSA-Key based authentication.

func WithTracerProvider added in v0.0.8

func WithTracerProvider(provider trace.TracerProvider) Opt

WithTracerProvider sets a custom OpenTelemetry TracerProvider for distributed tracing. If not set, the global tracer provider will be used.

func WithTransportCredentials

func WithTransportCredentials(creds credentials.TransportCredentials) Opt

WithTransportCredentials sets the transport custom credentials for the ChipIngress service.

type PingResponse

type PingResponse = pb.PingResponse

type PublishResponse

type PublishResponse = pb.PublishResponse

type PublishResult

type PublishResult = pb.PublishResult

type StreamEventsRequest

type StreamEventsRequest = pb.StreamEventsRequest

type StreamEventsResponse

type StreamEventsResponse = pb.StreamEventsResponse

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL