-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from atlassian/msg/inno-otlp-backend
Backend: Adding initial OTLP types for new OTLP Backend
- Loading branch information
Showing
29 changed files
with
1,170 additions
and
11 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
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
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 otlp | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/atlassian/gostatsd" | ||
) | ||
|
||
const ( | ||
namedBackend = `otlp` | ||
) | ||
|
||
// Client contains additional meta data in order | ||
// to export values as OTLP metrics. | ||
// The zero value is not safe to use. | ||
type Client struct { | ||
resources []string | ||
} | ||
|
||
var _ gostatsd.Backend = (*Client)(nil) | ||
|
||
func (Client) Name() string { return namedBackend } | ||
|
||
func (Client) SendEvent(ctx context.Context, e *gostatsd.Event) error { | ||
return nil | ||
} | ||
|
||
func (Client) SendMetricsAsync(ctx context.Context, mm *gostatsd.MetricMap, cb gostatsd.SendCallback) { | ||
cb(nil) | ||
} |
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 @@ | ||
package otlp |
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,23 @@ | ||
package data | ||
|
||
import ( | ||
v1metrics "go.opentelemetry.io/proto/otlp/metrics/v1" | ||
) | ||
|
||
type Gauge struct { | ||
raw *v1metrics.Gauge | ||
} | ||
|
||
func NewGauge(datapoints ...NumberDataPoint) Gauge { | ||
g := Gauge{ | ||
raw: &v1metrics.Gauge{ | ||
DataPoints: make([]*v1metrics.NumberDataPoint, 0, len(datapoints)), | ||
}, | ||
} | ||
|
||
for i := 0; i < len(datapoints); i++ { | ||
g.raw.DataPoints = append(g.raw.DataPoints, datapoints[i].raw) | ||
} | ||
|
||
return g | ||
} |
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,17 @@ | ||
package data | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGauge(t *testing.T) { | ||
t.Parallel() | ||
|
||
g := NewGauge() | ||
assert.Len(t, g.raw.DataPoints, 0, "Must have no datapoints defined") | ||
|
||
g = NewGauge(NewNumberDataPoint(100), NewNumberDataPoint(100)) | ||
assert.Len(t, g.raw.DataPoints, 2, "Must have two datapoints defined") | ||
} |
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,87 @@ | ||
package data | ||
|
||
import ( | ||
"math" | ||
"slices" | ||
|
||
v1metrics "go.opentelemetry.io/proto/otlp/metrics/v1" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
type Histogram struct { | ||
raw *v1metrics.Histogram | ||
} | ||
|
||
type HistogramDataPoint struct { | ||
raw *v1metrics.HistogramDataPoint | ||
} | ||
|
||
func NewHistogram(datapoints ...HistogramDataPoint) Histogram { | ||
ht := Histogram{ | ||
raw: &v1metrics.Histogram{ | ||
AggregationTemporality: v1metrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, | ||
DataPoints: make([]*v1metrics.HistogramDataPoint, 0, len(datapoints)), | ||
}, | ||
} | ||
|
||
for i := 0; i < len(datapoints); i++ { | ||
ht.raw.DataPoints = append( | ||
ht.raw.DataPoints, | ||
datapoints[i].raw, | ||
) | ||
} | ||
|
||
return ht | ||
} | ||
|
||
func WithHistogramDataPointAttributes(attrs Map) func(HistogramDataPoint) { | ||
return func(hdp HistogramDataPoint) { | ||
hdp.raw.Attributes = attrs.unwrap() | ||
} | ||
} | ||
|
||
func WithHistogramDataPointStatistics(values []float64) func(HistogramDataPoint) { | ||
return func(hdp HistogramDataPoint) { | ||
hdp.raw.Sum = new(float64) | ||
hdp.raw.Min = &values[0] | ||
hdp.raw.Max = &values[len(values)-1] | ||
hdp.raw.Count = uint64(len(values)) | ||
|
||
for _, v := range values { | ||
*hdp.raw.Sum += v | ||
*hdp.raw.Min = math.Min(*hdp.raw.Min, v) | ||
*hdp.raw.Max = math.Max(*hdp.raw.Max, v) | ||
} | ||
} | ||
} | ||
|
||
func WithHistogramDataPointBucketValues[Buckets ~map[float64]uint64](buckets Buckets) func(HistogramDataPoint) { | ||
return func(hdp HistogramDataPoint) { | ||
bounds := maps.Keys(buckets) | ||
slices.Sort(bounds) | ||
|
||
hdp.raw.BucketCounts = make([]uint64, len(buckets)) | ||
hdp.raw.ExplicitBounds = make([]float64, len(buckets)-1) | ||
|
||
for i, bound := range bounds { | ||
hdp.raw.BucketCounts[i] = buckets[bound] | ||
if !math.IsInf(bound, 1) { | ||
hdp.raw.ExplicitBounds[i] = bound | ||
} | ||
} | ||
} | ||
} | ||
|
||
func NewHistogramDataPoint(timestamp uint64, opts ...func(HistogramDataPoint)) HistogramDataPoint { | ||
dp := HistogramDataPoint{ | ||
raw: &v1metrics.HistogramDataPoint{ | ||
TimeUnixNano: timestamp, | ||
}, | ||
} | ||
|
||
for i := 0; i < len(opts); i++ { | ||
opts[i](dp) | ||
} | ||
|
||
return dp | ||
} |
Oops, something went wrong.