core

package module
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

README

GoDoc

core

import "github.com/go-coldbrew/core"

package core is the core module for cold brew and provides the base implementation for Cold Brew.

The idea behind cold brew is simple, we want to reuse as many good components that we can by providing only a thin wrapper around them if needed.

The components in use by cold brew currently are

github.com/grpc-ecosystem/grpc-gateway
github.com/prometheus/client_golang
github.github.com/afex/hystrix-go
github.com/opentracing/opentracing-go
github.com/newrelic/go-agent

The core module provides the base implementation for Cold Brew. It provides the following features

  • A base implementation for a gRPC server
  • A base implementation for a gRPC gateway
  • A base implementation for health check
  • A base implementation for metrics
  • A base implementation for a circuit breaker
  • A base implementation for a tracing
  • A base implementation for a new relic
  • A base implementation for a logger
  • A base implementation for a gRPC server reflection

The core module is the base module for cold brew and provides the base implementation for Cold Brew. It works in conjunction with the other modules to provide the full functionality of Cold Brew. To get started with Cold Brew, you can use cookiecutter to generate a new project from the template. The template can be found at https://github.com/go-coldbrew/cookiecutter-coldbrew

Index

func ConfigureInterceptors

func ConfigureInterceptors(DoNotLogGRPCReflection bool, traceHeaderName string)

ConfigureInterceptors configures the interceptors package with the provided DoNotLogGRPCReflection is a boolean that indicates whether to log the grpc.reflection.v1alpha.ServerReflection service calls in logs traceHeaderName is the name of the header to use for tracing (e.g. X-Trace-Id) - if empty, defaults to X-Trace-Id

func InitializeVTProto

func InitializeVTProto()

InitializeVTProto initializes the vtproto package for use with the service

https://github.com/planetscale/vtprotobuf?tab=readme-ov-file#mixing-protobuf-implementations-with-grpc

func SetupAutoMaxProcs

func SetupAutoMaxProcs()

SetupAutoMaxProcs sets up the GOMAXPROCS to match Linux container CPU quota This is used to set the GOMAXPROCS to the number of CPUs allocated to the container

func SetupEnvironment

func SetupEnvironment(env string)

SetupEnvironment sets the environment This is used to identify the environment in Sentry and New Relic env is the environment to set for the service (e.g. prod, staging, dev)

func SetupHystrixPrometheus

func SetupHystrixPrometheus()

SetupHystrixPrometheus sets up the hystrix metrics This is a workaround for hystrix-go not supporting the prometheus registry

func SetupLogger

func SetupLogger(logLevel string, jsonlogs bool) error

SetupLogger sets up the logger It uses the coldbrew logger to log messages to stdout logLevel is the log level to set for the logger jsonlogs is a boolean to enable or disable json logs

func SetupNROpenTelemetry

func SetupNROpenTelemetry(serviceName, license, version string, ratio float64) error

setupOpenTelemetry sets up the OpenTelemetry tracing It uses the New Relic OTLP exporter to send traces to New Relic One APM and Insights serviceName is the name of the service license is the New Relic license key version is the version of the service ratio is the sampling ratio to use for traces

func SetupNewRelic

func SetupNewRelic(serviceName, apiKey string, tracing bool) error

SetupNewRelic sets up the New Relic tracing and monitoring agent for the service It uses the New Relic Go Agent to send traces to New Relic One APM and Insights serviceName is the name of the service apiKey is the New Relic license key tracing is a boolean to enable or disable tracing

func SetupReleaseName

func SetupReleaseName(rel string)

SetupReleaseName sets the release name This is used to identify the release in Sentry rel is the release name to set for the service (e.g. v1.0.0)

func SetupSentry

func SetupSentry(dsn string)

SetupSentry sets up the Sentry notifier It uses the Sentry HTTP Transport to send errors to Sentry server dsn is the Sentry DSN to use for sending errors

type CB

CB is the interface that wraps coldbrew methods.

type CB interface {
    // SetService sets the service.
    SetService(CBService) error
    // Run runs the service.
    // Run is blocking. It returns an error if the service fails. Otherwise, it returns nil.
    Run() error
    // SetOpenAPIHandler sets the OpenAPI handler.
    SetOpenAPIHandler(http.Handler)
    // Stop stops the service.
    // Stop is blocking. It returns an error if the service fails. Otherwise, it returns nil.
    // duration is the duration to wait for the service to stop.
    Stop(time.Duration) error
}

func New
func New(c config.Config) CB

New creates a new ColdBrew object It takes a config object and returns a CB interface The CB interface is used to start and stop the server The CB interface also provides a way to add services to the server The services are added using the AddService method The services are started and stopped in the order they are added

type CBGracefulStopper

CBGracefulStopper is the interface that wraps the graceful stop method.

type CBGracefulStopper interface {
    // FailCheck set if the service is ready to stop.
    // FailCheck is called by the core package.
    FailCheck(bool)
}

type CBService

CBService is the interface that wraps service methods used in ColdBrew. InitHTTP initializes the HTTP server. InitGRPC initializes the gRPC server. InitHTTP and InitGRPC are called by the core package.

type CBService interface {
    // InitHTTP initializes the HTTP server
    // mux is the HTTP server mux to register the service.
    // endpoint is the gRPC endpoint to connect.
    // opts is the gRPC dial options used to connect to the endpoint.
    InitHTTP(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error
    // InitGRPC initializes the gRPC server
    // server is the gRPC server to register the service.
    InitGRPC(ctx context.Context, server *grpc.Server) error
}

type CBStopper

CBStopper is the interface that wraps the stop method.

type CBStopper interface {
    // Stop stops the service.
    // Stop is called by the core package.
    Stop()
}

Generated by gomarkdoc

Documentation

Overview

package core is the core module for cold brew and provides the base implementation for Cold Brew.

The idea behind cold brew is simple, we want to reuse as many good components that we can by providing only a thin wrapper around them if needed.

The components in use by cold brew currently are

github.com/grpc-ecosystem/grpc-gateway
github.com/prometheus/client_golang
github.github.com/afex/hystrix-go
github.com/opentracing/opentracing-go
github.com/newrelic/go-agent

The core module provides the base implementation for Cold Brew. It provides the following features

  • A base implementation for a gRPC server
  • A base implementation for a gRPC gateway
  • A base implementation for health check
  • A base implementation for metrics
  • A base implementation for a circuit breaker
  • A base implementation for a tracing
  • A base implementation for a new relic
  • A base implementation for a logger
  • A base implementation for a gRPC server reflection

The core module is the base module for cold brew and provides the base implementation for Cold Brew. It works in conjunction with the other modules to provide the full functionality of Cold Brew. To get started with Cold Brew, you can use cookiecutter to generate a new project from the template. The template can be found at https://github.com/go-coldbrew/cookiecutter-coldbrew

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureInterceptors added in v0.1.18

func ConfigureInterceptors(DoNotLogGRPCReflection bool, traceHeaderName string)

ConfigureInterceptors configures the interceptors package with the provided DoNotLogGRPCReflection is a boolean that indicates whether to log the grpc.reflection.v1alpha.ServerReflection service calls in logs traceHeaderName is the name of the header to use for tracing (e.g. X-Trace-Id) - if empty, defaults to X-Trace-Id

func InitializeVTProto added in v0.1.23

func InitializeVTProto()

InitializeVTProto initializes the vtproto package for use with the service

https://github.com/planetscale/vtprotobuf?tab=readme-ov-file#mixing-protobuf-implementations-with-grpc

func SetupAutoMaxProcs added in v0.1.19

func SetupAutoMaxProcs()

SetupAutoMaxProcs sets up the GOMAXPROCS to match Linux container CPU quota This is used to set the GOMAXPROCS to the number of CPUs allocated to the container

func SetupEnvironment added in v0.1.18

func SetupEnvironment(env string)

SetupEnvironment sets the environment This is used to identify the environment in Sentry and New Relic env is the environment to set for the service (e.g. prod, staging, dev)

func SetupHystrixPrometheus added in v0.1.18

func SetupHystrixPrometheus()

SetupHystrixPrometheus sets up the hystrix metrics This is a workaround for hystrix-go not supporting the prometheus registry

func SetupLogger added in v0.1.18

func SetupLogger(logLevel string, jsonlogs bool) error

SetupLogger sets up the logger It uses the coldbrew logger to log messages to stdout logLevel is the log level to set for the logger jsonlogs is a boolean to enable or disable json logs

func SetupNROpenTelemetry added in v0.1.18

func SetupNROpenTelemetry(serviceName, license, version string, ratio float64) error

setupOpenTelemetry sets up the OpenTelemetry tracing It uses the New Relic OTLP exporter to send traces to New Relic One APM and Insights serviceName is the name of the service license is the New Relic license key version is the version of the service ratio is the sampling ratio to use for traces

func SetupNewRelic added in v0.1.18

func SetupNewRelic(serviceName, apiKey string, tracing bool) error

SetupNewRelic sets up the New Relic tracing and monitoring agent for the service It uses the New Relic Go Agent to send traces to New Relic One APM and Insights serviceName is the name of the service apiKey is the New Relic license key tracing is a boolean to enable or disable tracing

func SetupReleaseName added in v0.1.18

func SetupReleaseName(rel string)

SetupReleaseName sets the release name This is used to identify the release in Sentry rel is the release name to set for the service (e.g. v1.0.0)

func SetupSentry added in v0.1.18

func SetupSentry(dsn string)

SetupSentry sets up the Sentry notifier It uses the Sentry HTTP Transport to send errors to Sentry server dsn is the Sentry DSN to use for sending errors

Types

type CB

type CB interface {
	// SetService sets the service.
	SetService(CBService) error
	// Run runs the service.
	// Run is blocking. It returns an error if the service fails. Otherwise, it returns nil.
	Run() error
	// SetOpenAPIHandler sets the OpenAPI handler.
	SetOpenAPIHandler(http.Handler)
	// Stop stops the service.
	// Stop is blocking. It returns an error if the service fails. Otherwise, it returns nil.
	// duration is the duration to wait for the service to stop.
	Stop(time.Duration) error
}

CB is the interface that wraps coldbrew methods.

func New

func New(c config.Config) CB

New creates a new ColdBrew object It takes a config object and returns a CB interface The CB interface is used to start and stop the server The CB interface also provides a way to add services to the server The services are added using the AddService method The services are started and stopped in the order they are added

type CBGracefulStopper added in v0.1.7

type CBGracefulStopper interface {
	// FailCheck set if the service is ready to stop.
	// FailCheck is called by the core package.
	FailCheck(bool)
}

CBGracefulStopper is the interface that wraps the graceful stop method.

type CBService

type CBService interface {
	// InitHTTP initializes the HTTP server
	// mux is the HTTP server mux to register the service.
	// endpoint is the gRPC endpoint to connect.
	// opts is the gRPC dial options used to connect to the endpoint.
	InitHTTP(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error
	// InitGRPC initializes the gRPC server
	// server is the gRPC server to register the service.
	InitGRPC(ctx context.Context, server *grpc.Server) error
}

CBService is the interface that wraps service methods used in ColdBrew. InitHTTP initializes the HTTP server. InitGRPC initializes the gRPC server. InitHTTP and InitGRPC are called by the core package.

type CBStopper added in v0.1.1

type CBStopper interface {
	// Stop stops the service.
	// Stop is called by the core package.
	Stop()
}

CBStopper is the interface that wraps the stop method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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