-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Ludinard
committed
Aug 21, 2023
0 parents
commit 483c1a4
Showing
26 changed files
with
1,562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
.env | ||
.values.yaml | ||
.helmfile.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM scratch | ||
|
||
USER 1000 | ||
|
||
COPY --chown=1000 --chmod=755 ./build/snooze-otlp /snooze-otlp | ||
|
||
CMD ["/snooze-otlp", "run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
APP_VERSION := v1.0.0 | ||
export CHART_VERSION := $(shell grep -oP 'version: \K.*' charts/snooze-otlp/Chart.yaml) | ||
|
||
.PHONY: build develop release go_build docker_build | ||
|
||
go_build: | ||
mkdir -p build | ||
CGO_ENABLED=0 GOOS=linux go build -v \ | ||
-ldflags "-X github.com/japannext/snooze-otlp/server.Version=$(APP_VERSION) -w -s" \ | ||
-o build/snooze-otlp-$(APP_VERSION) \ | ||
. | ||
ln -nsf ./snooze-otlp-$(APP_VERSION) build/snooze-otlp.latest | ||
cp build/snooze-otlp-$(APP_VERSION) build/snooze-otlp | ||
|
||
docker_build: | ||
docker build . | ||
|
||
build: go_build docker_build | ||
|
||
develop: go_build | ||
scripts/develop.sh | ||
|
||
release: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# snooze-otlp | ||
|
||
A Snooze opentelemetry log input plugin. | ||
|
||
Listen on gRPC for opentelemetry /v1/logs for log inputs, | ||
and forward them to a snooze instance in the correct format. | ||
|
||
# Deployment | ||
|
||
## Helm chart | ||
|
||
```bash | ||
helm repo add jnx japannext.github.com/helm-charts | ||
helm install jnx/snooze-otlp -f values.yaml | ||
``` | ||
|
||
Example of a basic configuration: | ||
```yaml | ||
# values.yaml | ||
snooze: | ||
url: https://snooze.example.com | ||
caConfigMap: ca-bundle # from trust-manager for instance | ||
``` | ||
## Docker | ||
```bash | ||
docker run ghcr.io/japannext/snooze-otlp:latest \ | ||
--env-file env.list \ | ||
-v /etc/pki/tls/cert.pem:/tls/ca.crt:ro | ||
``` | ||
|
||
```bash | ||
# env.list | ||
SNOOZE_OTLP_SNOOZE_URL=https://snooze.example.com | ||
SNOOZE_OTLP_CA_PATH=/tls/ca.crt | ||
``` | ||
|
||
## Binary | ||
|
||
WIP | ||
|
||
# opentelemetry-collector | ||
|
||
Here is an example of opentelemetry-collector configuration: | ||
```yaml | ||
--- | ||
# WIP | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
apiVersion: v2 | ||
name: snooze-otlp | ||
version: 1.0.0 | ||
appVersion: 1.0.0 | ||
description: | | ||
Opentelemetry input plugin for snooze. Listen | ||
on opentelemetry gRPC, and send alerts to | ||
a snooze URL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: "{{ .Release.Name }}" | ||
namespace: "{{ .Release.Namespace }}" | ||
labels: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ .Release.Name }}" | ||
app.kubernetes.io/component: otlp-listener | ||
app.kubernetes.io/part-of: "{{ .Values.partOf }}" | ||
spec: | ||
replicas: {{ .Values.replicas }} | ||
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ .Release.Name }}" | ||
template: | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ .Release.Name }}" | ||
app.kubernetes.io/component: otlp-listener | ||
app.kubernetes.io/part-of: "{{ .Values.partOf }}" | ||
{{- if .Values.podAnnotations }} | ||
annotations: {{- toYaml .Values.podAnnotations | nindent 8 }} | ||
{{- end }} | ||
spec: | ||
containers: | ||
- name: snooze-otlp | ||
image: "{{ .Values.image.repo }}/{{ .Values.image.name }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: "{{ .Values.image.pullPolicy }}" | ||
ports: | ||
- name: otlp-grpc | ||
containerPort: {{ toYaml .Values.otlp.grpcPort }} | ||
protocol: TCP | ||
{{- if .Values.prometheus.enabled }} | ||
- name: metrics | ||
containerPort: {{ toYaml .Values.prometheus.port }} | ||
protocol: TCP | ||
{{- end }} | ||
resources: | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
capabilities: {drop: ['ALL']} | ||
runAsNonRoot: true | ||
seccompProfile: {type: RuntimeDefault} | ||
env: | ||
- name: SNOOZE_OTLP_GRPC_LISTENING_PORT | ||
value: "{{ toYaml .Values.otlp.grpcPort }}" | ||
- name: SNOOZE_OTLP_SNOOZE_URL | ||
value: "{{ .Values.snooze.url }}" | ||
{{- if .Values.snooze.caConfigMap }} | ||
- name: SNOOZE_OTLP_SNOOZE_CA_PATH | ||
value: "/etc/ssl/certs/ca-certificates.crt" | ||
{{- end }} | ||
- name: SNOOZE_OTLP_LOG_LEVEL | ||
value: "{{ .Values.logLevel }}" | ||
{{- with .Values.prometheus }} | ||
- name: SNOOZE_OTLP_PROMETHEUS_ENABLE | ||
value: "{{ .enabled }}" | ||
- name: SNOOZE_OTLP_PROMETHEUS_PORT | ||
value: "{{ .port }}" | ||
{{- end }} | ||
{{- if .Values.snooze.caConfigMap }} | ||
volumeMounts: | ||
- name: cacert | ||
mountPath: "/etc/ssl/certs/ca-certificates.crt" | ||
subPath: ca.crt | ||
{{- end }} | ||
livenessProbe: | ||
grpc: | ||
port: {{ .Values.otlp.grpcPort }} | ||
initialDelaySeconds: 3 | ||
readinessProbe: | ||
grpc: | ||
port: {{ .Values.otlp.grpcPort }} | ||
initialDelaySeconds: 3 | ||
{{- if .Values.snooze.caConfigMap }} | ||
volumes: | ||
- name: cacert | ||
configMap: | ||
name: "{{- .Values.snooze.caConfigMap }}" | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{- with .Values.prometheus.podMonitor }} | ||
{{- if .enabled }} | ||
--- | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: PodMonitor | ||
metadata: | ||
name: "{{ $.Release.Name }}" | ||
namespace: "{{ $.Release.Namespace }}" | ||
labels: {{ toYaml .labels | nindent 4 }} | ||
spec: | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ $.Release.Name }}" | ||
podMetricsEndpoints: | ||
- path: /metrics | ||
port: metrics | ||
scheme: http | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: "{{ .Release.Name }}" | ||
namespace: "{{ .Release.Namespace }}" | ||
labels: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ .Release.Name }}" | ||
app.kubernetes.io/component: otlp-listener | ||
app.kubernetes.io/part-of: "{{ .Values.partOf }}" | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- port: 4317 | ||
targetPort: otlp-grpc | ||
protocol: TCP | ||
selector: | ||
app.kubernetes.io/name: snooze-otlp | ||
app.kubernetes.io/instance: "{{ .Release.Name }}" | ||
sessionAffinity: None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
replicas: 2 | ||
revisionHistoryLimit: 3 | ||
|
||
partOf: snooze | ||
|
||
# The log level of the application. | ||
# Accepted values: trace/debug/info/warning/error/fatal/panic | ||
logLevel: "info" | ||
|
||
podAnnotations: {} | ||
|
||
prometheus: | ||
enabled: true | ||
port: 9317 | ||
podMonitor: | ||
enabled: false | ||
labels: {} | ||
|
||
image: | ||
name: snooze-otlp | ||
repo: ghrc.io/japannext/snooze-otlp | ||
tag: "" | ||
pullPolicy: IfNotPresent | ||
|
||
otlp: | ||
grpcPort: 4317 | ||
|
||
snooze: | ||
url: "" | ||
caConfigMap: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/japannext/snooze-otlp/server" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "snooze-otlp", | ||
Short: "", | ||
Long: ``, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(server.InitServer) | ||
|
||
rootCmd.AddCommand(runCmd) | ||
rootCmd.AddCommand(versionCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/japannext/snooze-otlp/server" | ||
) | ||
|
||
var runCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "Run the snooze-otlp service", | ||
Long: `Run the snooze-otlp service. This will listen on Opentelemetry port | ||
for opentelemetry gRPC format. Upon receiving a log at /v1/logs, it will | ||
send it to snooze in the appropriate format (snooze v1)`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
server.Run() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/japannext/snooze-otlp/server" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Display snooze-otlp version", | ||
Long: "Display snooze-otlp version", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
server.PrintVersion() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module github.com/japannext/snooze-otlp | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/prometheus/client_golang v1.16.0 | ||
github.com/sirupsen/logrus v1.9.3 | ||
github.com/spf13/cobra v1.7.0 | ||
github.com/spf13/viper v1.16.0 | ||
github.com/stretchr/testify v1.8.4 | ||
go.opentelemetry.io/proto/otlp v1.0.0 | ||
google.golang.org/grpc v1.57.0 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/prometheus/client_model v0.3.0 // indirect | ||
github.com/prometheus/common v0.42.0 // indirect | ||
github.com/prometheus/procfs v0.10.1 // indirect | ||
github.com/spf13/afero v1.9.5 // indirect | ||
github.com/spf13/cast v1.5.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.4.2 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.