Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Prometheus remote write receiver compatible with sfx gateway #3064

Merged
merged 56 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d189b6f
Add initial prometheus translation logic, for only sfx compatibility
hughesjj Apr 26, 2023
911a625
add timeout to test client
hughesjj May 4, 2023
813090a
refactor naming for test helpers
hughesjj May 4, 2023
ca43691
more comprehensive testing
hughesjj May 4, 2023
3bb2811
make fmt
hughesjj May 4, 2023
e0e6fde
I think this matches what we do with nans, reporting the metric but n…
hughesjj May 4, 2023
e9cd002
add comment about metricdata support
hughesjj May 4, 2023
3abc8f9
Think this fixes remaining issues with accounting on sfx specific err…
hughesjj May 4, 2023
d8abaed
move scopemetrics up
hughesjj May 4, 2023
2d46aca
ahh histograms
hughesjj May 4, 2023
b76ba59
expand readme to reflect things no longer reported
hughesjj May 4, 2023
574c4d8
test timestamps too, can handle better test pattern later
hughesjj May 4, 2023
c36e7a0
tidy commit
hughesjj May 4, 2023
45072ca
godoc format some docstrings in utils
hughesjj May 4, 2023
5ea3075
rename utils to something more meaningful (prometheus_spec_utils)
hughesjj May 4, 2023
dbae0cf
remove stateset, add documentation for the newly releases PRW spec 1.0
hughesjj May 4, 2023
bd70c67
reduce timeout in test
hughesjj May 4, 2023
5abd8de
remote outdated comment
hughesjj May 4, 2023
58a5db1
more comment and test cleanup
hughesjj May 4, 2023
264dde2
remove logs from test
hughesjj May 4, 2023
4e6a7ce
add test for summary
hughesjj May 4, 2023
ca6b1cc
fix test for summary
hughesjj May 4, 2023
a2c2329
fix docstring
hughesjj May 4, 2023
78e25f8
Update internal/receiver/prometheusremotewritereceiver/config.go
hughesjj May 4, 2023
e14033b
Update internal/receiver/prometheusremotewritereceiver/README.md
hughesjj May 4, 2023
9defbdf
PR feedback
hughesjj May 4, 2023
e11a4f5
Make Readme more accurate
hughesjj May 4, 2023
92e2bdf
bit more comprehensive tsting of metric recipience. Would love to ad…
hughesjj May 5, 2023
3b4ef37
test some error cases as well
hughesjj May 5, 2023
8d5b3e5
PR Feedback on prometheus_spec_utils
hughesjj May 7, 2023
32fecf2
de-export some things
hughesjj May 7, 2023
70539b5
combine write request fixtures into single _test file
hughesjj May 7, 2023
bfbe16c
remove set in favor of map in test
hughesjj May 7, 2023
6df70ba
use map equality instead of set comparison -- but stop caring about o…
hughesjj May 7, 2023
c4d8774
rework readme to conform to new shape
hughesjj May 7, 2023
2f82738
make fmt
hughesjj May 7, 2023
9a275b8
rename receiver
hughesjj May 7, 2023
7287c77
rename typestring to signalfxgatewayprometheusremotewrite
hughesjj May 7, 2023
aa1b1a5
adopt new receiver into components
hughesjj May 7, 2023
2a2e8ca
fix lint
hughesjj May 7, 2023
bc3f427
mdatagen alignment
hughesjj May 7, 2023
0d0afaf
add an example for running sfx gateway prometheus remote write receiver
hughesjj May 7, 2023
90339c0
aha, thought so. anyway new convienence methods to prevent this
hughesjj May 8, 2023
e6ee90f
needs makefile to pass forall command in workflows
hughesjj May 8, 2023
514be69
change logging config due to deprecated setting
hughesjj May 8, 2023
59ee3de
ensure we set telemetry settings
hughesjj May 8, 2023
ec92702
ah, telemetry endpoint conflicts. Looking into what that setting act…
hughesjj May 8, 2023
ed057ab
oops, misread, we actually don't want this particular one set (MeterP…
hughesjj May 8, 2023
5778e40
allow for more retries...
hughesjj May 8, 2023
9deee61
add license to example golang file & other various cleanup of example
hughesjj May 8, 2023
55a9e90
another lint check... think I need to test with for-all locally and n…
hughesjj May 8, 2023
1f49e2c
get rid of anything to do with metricfamily name and fully adhere to …
hughesjj May 8, 2023
34bb393
lintfixes
hughesjj May 8, 2023
9c2f54e
cleanup README and lingering comments pre merge (hopefully 🤞)
hughesjj May 8, 2023
a6ecef7
Update internal/receiver/signalfxgatewayprometheusremotewritereceiver…
hughesjj May 8, 2023
0e428ea
use errors not fmt
hughesjj May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.19-alpine AS builder
WORKDIR /app
COPY fake-metrics-generator.go go.mod go.sum ./
RUN CGO_ENABLED=0 GOOS=linux go build -o fake-metrics-generator

FROM alpine:3.14
WORKDIR /app
COPY --from=builder /app/fake-metrics-generator .
CMD ["./fake-metrics-generator"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
hughesjj marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions examples/signalfxgatewayprometheusremotewritereceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SignalFx Gateway Prometheus Remote write Receiver Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit long(ish). Can we shorten to, say, Prometheus remote write example?


This example provides a `docker-compose` environment that continually sends some fake prometheus remote writes to an otel receiver replacement for the deprecated SignalFx Gateway for Prometheus Remote Writes.
To run this, ensure you have `docker-compose` installed.

Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This example provides a `docker-compose` environment that continually sends some fake prometheus remote writes to an otel receiver replacement for the deprecated SignalFx Gateway for Prometheus Remote Writes.
To run this, ensure you have `docker-compose` installed.
This example provides a `docker-compose` environment that continually sends fake prometheus remote writes to an OTel receiver replacement for the deprecated SignalFx Gateway for Prometheus Remote Writes. To run the example, make sure you have `docker-compose` installed.

## Configuration
You can change the exporters to your liking by modifying `otel-collector-config.yaml`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can change the exporters to your liking by modifying `otel-collector-config.yaml`.
To change the exporters, edit the `otel-collector-config.yaml` configuration file.


Ensure the following environment variables are properly set, should you wish to send data to splunk observability cloud:
1. `SPLUNK_ACCESS_TOKEN`
2. `SPLUNK_REALM`

Alternatively, you can remove the `signalfx` array item from the `exporters` configuration map in `otel-collector-config.yaml`

Feel free to modify the sample client to your liking, or even disable it and write your own!
Comment on lines +9 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ensure the following environment variables are properly set, should you wish to send data to splunk observability cloud:
1. `SPLUNK_ACCESS_TOKEN`
2. `SPLUNK_REALM`
Alternatively, you can remove the `signalfx` array item from the `exporters` configuration map in `otel-collector-config.yaml`
Feel free to modify the sample client to your liking, or even disable it and write your own!
If you want to send data to Splunk Observability Cloud, set the following environment variables:
-`SPLUNK_ACCESS_TOKEN`
-`SPLUNK_REALM`
You can also remove the `signalfx` array item from the `exporters` configuration map in the `otel-collector-config.yaml` configuration file.
> **Tip:** Experiment and modify the sample client, or even disable it and write your own.


## Running
Once you've verified your environment, you can run the example by

```bash
$> docker-compose up
```

If everything is configured properly, logs with sample writes should start appearing in stdout shortly.
Comment on lines +17 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Running
Once you've verified your environment, you can run the example by
```bash
$> docker-compose up
```
If everything is configured properly, logs with sample writes should start appearing in stdout shortly.
## Run the example
After you've verified your environment, enter the following command to run the example:
```bash
$> docker-compose up

If everything is configured properly, logs with sample writes start appearing in stdout.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.1"
services:
otelcollector:
image: otelcol:latest
container_name: otelcollector
environment:
- SPLUNK_ACCESS_TOKEN=${SPLUNK_ACCESS_TOKEN}
- SPLUNK_REALM=${SPLUNK_REALM}
command: ["--config=/etc/otel-collector-config.yaml", "--set=service.telemetry.logs.level=debug"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
ports:
- "19291:19291"
- "8888:8888"

fake_metrics_generator:
build:
context: .
dockerfile: Dockerfile.fake-metrics-generator
depends_on:
- otelcollector
environment:
- TARGET_URL=http://otelcollector:19291/metrics
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright OpenTelemetry Authors
// Copyright Splunk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"net/url"
"os"
"time"

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/prometheus/common/config"
"github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/storage/remote"
)

func main() {

URL := &config.URL{
URL: &url.URL{
Scheme: "http",
Host: os.Getenv("endpoint"),
Path: os.Getenv("path"),
},
}
cfg := &remote.ClientConfig{
URL: URL,
HTTPClientConfig: config.HTTPClientConfig{},
}
client, err := remote.NewWriteClient("mock_prw_client", cfg)
if err != nil {
panic(err)
}

metrics := []prompb.TimeSeries{
{
Labels: []prompb.Label{
{Name: "__name__", Value: "fake_metric_total"},
{Name: "instance", Value: cfg.URL.Host},
},
Samples: []prompb.Sample{
{Value: 42, Timestamp: time.Now().UnixMilli()},
},
},
}

req := &prompb.WriteRequest{
Timeseries: metrics,
}
compressed := encodeWriteRequest(req)

for {
client.Store(context.Background(), compressed)
time.Sleep(10 * time.Second)
}
}

func encodeWriteRequest(request *prompb.WriteRequest) []byte {
data, err := proto.Marshal(request)
if err != nil {
panic(err)
}

return snappy.Encode(nil, data)
}
53 changes: 53 additions & 0 deletions examples/signalfxgatewayprometheusremotewritereceiver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module fake-metrics-generator

go 1.19

require (
github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.4
github.com/prometheus/common v0.42.0
github.com/prometheus/prometheus v0.43.1
)

require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aws/aws-sdk-go v1.44.217 // indirect
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/dennwc/varint v1.0.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.2.1 // indirect
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.29.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading