Skip to content

Commit

Permalink
Merge pull request #307 from openmeterio/export
Browse files Browse the repository at this point in the history
Export OpenMeter as a library
  • Loading branch information
sagikazarmark authored Oct 12, 2023
2 parents 4c85a64 + 5a897c1 commit 89b169f
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 0 deletions.
13 changes: 13 additions & 0 deletions openmeter/dedupe/dedupe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Package dedupe implements in-process event deduplication.
package dedupe

import (
"github.com/cloudevents/sdk-go/v2/event"

"github.com/openmeterio/openmeter/internal/dedupe"
)

// GetEventKey creates a unique key from an event.
func GetEventKey(namespace string, ev event.Event) string {
return dedupe.GetEventKey(namespace, ev)
}
14 changes: 14 additions & 0 deletions openmeter/dedupe/memorydedupe/memorydedupe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package memorydedupe implements in-memory event deduplication.
package memorydedupe

import (
"github.com/openmeterio/openmeter/internal/dedupe/memorydedupe"
)

// Deduplicator implements in-memory event deduplication.
type Deduplicator = memorydedupe.Deduplicator

// NewDeduplicator returns a new {Deduplicator}.
func NewDeduplicator(size int) (*Deduplicator, error) {
return memorydedupe.NewDeduplicator(size)
}
9 changes: 9 additions & 0 deletions openmeter/dedupe/redisdedupe/redisdedupe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package redisdedupe implements event deduplication using Redis.
package redisdedupe

import (
"github.com/openmeterio/openmeter/internal/dedupe/redisdedupe"
)

// Deduplicator implements event deduplication using Redis.
type Deduplicator = redisdedupe.Deduplicator
11 changes: 11 additions & 0 deletions openmeter/ingest/dedupe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ingest

import (
"github.com/openmeterio/openmeter/internal/ingest"
)

// Deduplicator checks if an event is unique.
type Deduplicator = ingest.Deduplicator

// DeduplicatingCollector implements event deduplication at event ingestion.
type DeduplicatingCollector = ingest.DeduplicatingCollector
14 changes: 14 additions & 0 deletions openmeter/ingest/httpingest/httpingest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package httpingest

import (
"github.com/openmeterio/openmeter/internal/ingest/httpingest"
)

// Handler receives an event in CloudEvents format and forwards it to a {Collector}.
type Handler = httpingest.Handler

type HandlerConfig = httpingest.HandlerConfig

func NewHandler(config HandlerConfig) (*Handler, error) {
return httpingest.NewHandler(config)
}
9 changes: 9 additions & 0 deletions openmeter/ingest/ingest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package ingest implements event ingestion.
package ingest

import (
"github.com/openmeterio/openmeter/internal/ingest"
)

// Collector is a receiver of events that handles sending those events to some downstream broker.
type Collector = ingest.Collector
8 changes: 8 additions & 0 deletions openmeter/ingest/inmemory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ingest

import (
"github.com/openmeterio/openmeter/internal/ingest"
)

// InMemoryCollector is a {Collector} backed by in-memory storage.
type InMemoryCollector = ingest.InMemoryCollector
17 changes: 17 additions & 0 deletions openmeter/ingest/kafkaingest/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kafkaingest

import (
"context"
"log/slog"

"github.com/confluentinc/confluent-kafka-go/v2/kafka"

"github.com/openmeterio/openmeter/internal/ingest/kafkaingest"
)

// Collector is a receiver of events that handles sending those events to a downstream Kafka broker.
type Collector = kafkaingest.Collector

func KafkaProducerGroup(ctx context.Context, producer *kafka.Producer, logger *slog.Logger) (execute func() error, interrupt func(error)) {
return kafkaingest.KafkaProducerGroup(ctx, producer, logger)
}
8 changes: 8 additions & 0 deletions openmeter/ingest/kafkaingest/namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kafkaingest

import (
"github.com/openmeterio/openmeter/internal/ingest/kafkaingest"
)

// NamespaceHandler is a namespace handler for Kafka ingest topics.
type NamespaceHandler = kafkaingest.NamespaceHandler
13 changes: 13 additions & 0 deletions openmeter/ingest/kafkaingest/serializer/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package serializer

import (
_ "embed"

"github.com/openmeterio/openmeter/internal/ingest/kafkaingest/serializer"
)

type JSONSerializer = serializer.JSONSerializer

func NewJSONSerializer() JSONSerializer {
return serializer.NewJSONSerializer()
}
11 changes: 11 additions & 0 deletions openmeter/ingest/kafkaingest/serializer/serializer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package serializer

import (
_ "embed"

"github.com/openmeterio/openmeter/internal/ingest/kafkaingest/serializer"
)

type Serializer = serializer.Serializer

type CloudEventsKafkaPayload = serializer.CloudEventsKafkaPayload
14 changes: 14 additions & 0 deletions openmeter/meter/inmemory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package meter

import (
"github.com/openmeterio/openmeter/internal/meter"
"github.com/openmeterio/openmeter/pkg/models"
)

// InMemoryRepository is an in-memory meter repository.
type InMemoryRepository = meter.InMemoryRepository

// NewInMemoryRepository returns a in-memory meter repository.
func NewInMemoryRepository(meters []models.Meter) *InMemoryRepository {
return meter.NewInMemoryRepository(meters)
}
8 changes: 8 additions & 0 deletions openmeter/meter/meter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package meter

import (
"github.com/openmeterio/openmeter/internal/meter"
)

// Repository is an interface to the meter store.
type Repository = meter.Repository
23 changes: 23 additions & 0 deletions openmeter/namespace/namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Package namespace adds a concept of tenancy to OpenMeter allowing to segment clients.
package namespace

import (
"github.com/openmeterio/openmeter/internal/namespace"
)

// Manager is responsible for managing namespaces in different components.
type Manager = namespace.Manager

type ManagerConfig = namespace.ManagerConfig

func NewManager(config ManagerConfig) (*Manager, error) {
return namespace.NewManager(config)
}

// Handler is responsible for creating a namespace in a given component.
//
// An empty name means a default namespace is supposed to be created.
// The concept of a default namespace is implementation specific.
//
// The behavior for trying to create a namespace that already exists is unspecified at the moment.
type Handler = namespace.Handler
2 changes: 2 additions & 0 deletions openmeter/openmeter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package openmeter is an experimental package to expose the core of OpenMeter as a library.
package openmeter
15 changes: 15 additions & 0 deletions openmeter/server/router/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package router

import (
"github.com/openmeterio/openmeter/internal/server/router"
)

type IngestHandler = router.IngestHandler

type Config = router.Config

type Router = router.Router

func NewRouter(config Config) (*Router, error) {
return router.NewRouter(config)
}
13 changes: 13 additions & 0 deletions openmeter/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package server

import (
"github.com/openmeterio/openmeter/internal/server"
)

type Server = server.Server

type Config = server.Config

func NewServer(config *Config) (*Server, error) {
return server.NewServer(config)
}
14 changes: 14 additions & 0 deletions openmeter/streaming/clickhouse_connector/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package clickhouse_connector

import (
"github.com/openmeterio/openmeter/internal/streaming/clickhouse_connector"
)

// ClickhouseConnector implements `ingest.Connector“ and `namespace.Handler interfaces.
type ClickhouseConnector = clickhouse_connector.ClickhouseConnector

type ClickhouseConnectorConfig = clickhouse_connector.ClickhouseConnectorConfig

func NewClickhouseConnector(config ClickhouseConnectorConfig) (*ClickhouseConnector, error) {
return clickhouse_connector.NewClickhouseConnector(config)
}
7 changes: 7 additions & 0 deletions openmeter/streaming/clickhouse_connector/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clickhouse_connector

import (
"github.com/openmeterio/openmeter/internal/streaming/clickhouse_connector"
)

type MeterView = clickhouse_connector.MeterView
13 changes: 13 additions & 0 deletions openmeter/streaming/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package streaming

import (
"github.com/openmeterio/openmeter/internal/streaming"
)

type ListEventsParams = streaming.ListEventsParams

type QueryParams = streaming.QueryParams

type QueryResult = streaming.QueryResult

type Connector = streaming.Connector

0 comments on commit 89b169f

Please sign in to comment.