Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
feat: add default exporters (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <mateusz.urbanek.98@gmail.com>
  • Loading branch information
shanduur authored Sep 27, 2023
1 parent 4cc2a19 commit 5506387
Show file tree
Hide file tree
Showing 14 changed files with 451 additions and 53 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
# Go workspace file
go.work

# OSP Folder
cosi-osp
# Demo
cosi-osp/
demo/
*.cast
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A Container Object Storage Interface (COSI) library and other helpful utilities
- [Contributing](#contributing)
- [Prior Art](#prior-art)

[![asciicast](https://asciinema.org/a/605022.svg)](https://asciinema.org/a/605022)
![gocosi usage demo](./resources/demo.gif)

## Quick Start

Expand Down Expand Up @@ -65,9 +65,6 @@ cosi-osp
|-------------------|-----------------------------------------|----------------------------------------------------------------|
| `-module` | `example.com/cosi-osp` | Override name for your new module. |
| `-dir` | `cosi-osp` | Location/Path, where the module will be created. |
| `-image` | `gcr.io/distroless/static:latest` | Override the default base Docker image. |
| `-rootless-image` | `docker.io/rockylinux/rockylinux:9-ubi` | Override the default base Docker image for rootless container. |
| `-rootless` | `false` | Generate the Dockerfile for rootless container. |

## Features

Expand Down Expand Up @@ -101,6 +98,26 @@ To cater to diverse logging preferences, the gocosi package seamlessly integrate
- `X_COSI_ENDPOINT_PERMS` (default: `0755`) - it should be set when the COSI endpoint is a UNIX socket file. It determines the file permissions (in octal notation) of the UNIX socket file. If the COSI endpoint is a TCP socket, this setting has no effect.
- `X_COSI_ENDPOINT_USER` (default: *The user that starts the process*) - it should be set when the COSI endpoint is a UNIX socket file. It determines the owner (user) of the UNIX socket file. If the COSI endpoint is a TCP socket, this setting has no effect.
- `X_COSI_ENDPOINT_GROUP` (default: *The group that starts the process*) - it should be set when the COSI endpoint is a UNIX socket file. It determines the group ownership of the UNIX socket file. If the COSI endpoint is a TCP socket, this setting has no effect.
- **Endpoint OTLP/HTTP** (default: `https://localhost:4317` or `https://localhost:4318`) - target URL to which the exporter is going to send spans or metrics. The endpoint MUST be a valid URL with scheme (http or https) and host, MAY contain a port, SHOULD contain a path and MUST NOT contain other parts (such as query string or fragment). [[spec]][otlp-exporter-spec]
- `OTEL_EXPORTER_OTLP_ENDPOINT`
- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
- `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
- **Certificate File** - the trusted certificate to use when verifying a server's TLS credentials. Should only be used for a secure connection. [[spec]][otlp-exporter-spec]
- `OTEL_EXPORTER_OTLP_CERTIFICATE`
- `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE`
- `OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE`
- **Headers** - key-value pairs to be used as headers associated with gRPC or HTTP requests. [[spec]][otlp-exporter-spec]
- `OTEL_EXPORTER_OTLP_HEADERS`
- `OTEL_EXPORTER_OTLP_TRACES_HEADERS`
- `OTEL_EXPORTER_OTLP_METRICS_HEADERS`
- **Compression** - compression key for supported compression types. Supported compression: `gzip`. [[spec]][otlp-exporter-spec]
- `OTEL_EXPORTER_OTLP_COMPRESSION`
- `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`
- `OTEL_EXPORTER_OTLP_METRICS_COMPRESSION`
- **Timeout** (default: `10s`) - maximum time the OTLP exporter will wait for each batch export. [[spec]][otlp-exporter-spec]
- `OTEL_EXPORTER_OTLP_TIMEOUT`
- `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`
- `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT`

## Contributing

Expand All @@ -109,3 +126,7 @@ You want to contibute? Hop into the [CONTRIBUTING.md](CONTRIBUTING.md) and find
## Prior Art

This project was inspired by [rexray/gocsi](https://github.com/rexray/gocsi) and [dell/gocsi](https://github.com/dell/gocsi).

<!-- Named Links --->

[otlp-exporter-spec]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md
2 changes: 1 addition & 1 deletion cmd/bootstrap/template/Dockerfile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ VOLUME [ "/var/lib/cosi" ]
HEALTHCHECK NONE

# Set the default environment.
ENV COSI_ENDPOINT="/var/lib/cosi/cosi.sock"
ENV COSI_ENDPOINT="unix:///var/lib/cosi/cosi.sock"
COPY --from=builder /cosi-osp/build/cosi-osp /usr/bin/cosi-osp

# Set the correct entrypoint and command arguments.
Expand Down
19 changes: 18 additions & 1 deletion cmd/bootstrap/template/main.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package main

import (
"context"
stdlog "log"
"os"

"github.com/doomshrine/gocosi"
"github.com/go-logr/logr"

"github.com/go-logr/stdr"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0" // FIXME: this might need manual update

"{{ .ModPath }}/servers/identity"
"{{ .ModPath }}/servers/provisioner"
)

var (
driverName = "cosi.example.com" // FIXME: replace with your own driver name
driverVersion = "v0.1.0" // FIXME: replace with your own driver version

exporterKind = gocosi.HTTPExporter

log logr.Logger
)
Expand All @@ -25,18 +31,29 @@ func init() {
// - https://github.com/go-logr/logr/tree/master/slogr
// - https://github.com/go-logr/stdr
// - https://github.com/bombsimon/logrusr
stdr.SetVerbosity(10)
log = stdr.New(stdlog.New(os.Stdout, "", stdlog.LstdFlags))
}

func main() {
gocosi.SetLogger(log)
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(driverName),
semconv.ServiceVersion(driverVersion),
)
// If there is any additional confifuration needed for your COSI Driver,
// put it below this line.
driver, err := gocosi.New(
identity.New(driverName, log),
provisioner.New(log),
res,
gocosi.WithDefaultGRPCOptions(),
gocosi.WithDefaultMetricExporter(exporterKind),
gocosi.WithDefaultTraceExporter(exporterKind),
)
if err != nil {
log.Error(err, "failed to create COSI Driver")
Expand Down
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@ require (
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.44.0
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.41.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.41.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.18.0
go.opentelemetry.io/otel/sdk v1.18.0
go.opentelemetry.io/otel/sdk/metric v0.41.0
google.golang.org/grpc v1.58.1
sigs.k8s.io/container-object-storage-interface-spec v0.1.0
)

require (
cloud.google.com/go/compute v1.21.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.41.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 5506387

Please sign in to comment.