Skip to content

Commit

Permalink
[pkg/telemetryquerylanguage] Expose Context's transform contexts (#12760
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TylerHelmuth authored Jul 30, 2022
1 parent fc194c3 commit 357dcdc
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 90 deletions.
20 changes: 10 additions & 10 deletions pkg/telemetryquerylanguage/contexts/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tql"
)

type logTransformContext struct {
log plog.LogRecord
il pcommon.InstrumentationScope
resource pcommon.Resource
type LogTransformContext struct {
Log plog.LogRecord
InstrumentationScope pcommon.InstrumentationScope
Resource pcommon.Resource
}

func (ctx logTransformContext) GetItem() interface{} {
return ctx.log
func (ctx LogTransformContext) GetItem() interface{} {
return ctx.Log
}

func (ctx logTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.il
func (ctx LogTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.InstrumentationScope
}

func (ctx logTransformContext) GetResource() pcommon.Resource {
return ctx.resource
func (ctx LogTransformContext) GetResource() pcommon.Resource {
return ctx.Resource
}

// pathGetSetter is a getSetter which has been resolved using a path expression provided by a user.
Expand Down
16 changes: 8 additions & 8 deletions pkg/telemetryquerylanguage/contexts/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,17 @@ func Test_newPathGetSetter(t *testing.T) {

log, il, resource := createTelemetry()

got := accessor.Get(logTransformContext{
log: log,
il: il,
resource: resource,
got := accessor.Get(LogTransformContext{
Log: log,
InstrumentationScope: il,
Resource: resource,
})
assert.Equal(t, tt.orig, got)

accessor.Set(logTransformContext{
log: log,
il: il,
resource: resource,
accessor.Set(LogTransformContext{
Log: log,
InstrumentationScope: il,
Resource: resource,
}, tt.newVal)

exSpan, exIl, exRes := createTelemetry()
Expand Down
58 changes: 29 additions & 29 deletions pkg/telemetryquerylanguage/contexts/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tql"
)

type metricTransformContext struct {
dataPoint interface{}
metric pmetric.Metric
metrics pmetric.MetricSlice
il pcommon.InstrumentationScope
resource pcommon.Resource
type MetricTransformContext struct {
DataPoint interface{}
Metric pmetric.Metric
Metrics pmetric.MetricSlice
InstrumentationScope pcommon.InstrumentationScope
Resource pcommon.Resource
}

func (ctx metricTransformContext) GetItem() interface{} {
return ctx.dataPoint
func (ctx MetricTransformContext) GetItem() interface{} {
return ctx.DataPoint
}

func (ctx metricTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.il
func (ctx MetricTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.InstrumentationScope
}

func (ctx metricTransformContext) GetResource() pcommon.Resource {
return ctx.resource
func (ctx MetricTransformContext) GetResource() pcommon.Resource {
return ctx.Resource
}

func (ctx metricTransformContext) GetMetric() pmetric.Metric {
return ctx.metric
func (ctx MetricTransformContext) GetMetric() pmetric.Metric {
return ctx.Metric
}

func (ctx metricTransformContext) GetMetrics() pmetric.MetricSlice {
return ctx.metrics
func (ctx MetricTransformContext) GetMetrics() pmetric.MetricSlice {
return ctx.Metrics
}

// pathGetSetter is a getSetter which has been resolved using a path expression provided by a user.
Expand Down Expand Up @@ -277,11 +277,11 @@ func accessInstrumentationScopeVersion() pathGetSetter {
func accessMetric() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
return ctx.(metricTransformContext).GetMetric()
return ctx.(MetricTransformContext).GetMetric()
},
setter: func(ctx tql.TransformContext, val interface{}) {
if newMetric, ok := val.(pmetric.Metric); ok {
newMetric.CopyTo(ctx.(metricTransformContext).GetMetric())
newMetric.CopyTo(ctx.(MetricTransformContext).GetMetric())
}
},
}
Expand All @@ -290,11 +290,11 @@ func accessMetric() pathGetSetter {
func accessMetricName() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
return ctx.(metricTransformContext).GetMetric().Name()
return ctx.(MetricTransformContext).GetMetric().Name()
},
setter: func(ctx tql.TransformContext, val interface{}) {
if str, ok := val.(string); ok {
ctx.(metricTransformContext).GetMetric().SetName(str)
ctx.(MetricTransformContext).GetMetric().SetName(str)
}
},
}
Expand All @@ -303,11 +303,11 @@ func accessMetricName() pathGetSetter {
func accessMetricDescription() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
return ctx.(metricTransformContext).GetMetric().Description()
return ctx.(MetricTransformContext).GetMetric().Description()
},
setter: func(ctx tql.TransformContext, val interface{}) {
if str, ok := val.(string); ok {
ctx.(metricTransformContext).GetMetric().SetDescription(str)
ctx.(MetricTransformContext).GetMetric().SetDescription(str)
}
},
}
Expand All @@ -316,11 +316,11 @@ func accessMetricDescription() pathGetSetter {
func accessMetricUnit() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
return ctx.(metricTransformContext).GetMetric().Unit()
return ctx.(MetricTransformContext).GetMetric().Unit()
},
setter: func(ctx tql.TransformContext, val interface{}) {
if str, ok := val.(string); ok {
ctx.(metricTransformContext).GetMetric().SetUnit(str)
ctx.(MetricTransformContext).GetMetric().SetUnit(str)
}
},
}
Expand All @@ -329,7 +329,7 @@ func accessMetricUnit() pathGetSetter {
func accessMetricType() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
return int64(ctx.(metricTransformContext).GetMetric().DataType())
return int64(ctx.(MetricTransformContext).GetMetric().DataType())
},
setter: func(ctx tql.TransformContext, val interface{}) {
// TODO Implement methods so correctly convert data types.
Expand All @@ -341,7 +341,7 @@ func accessMetricType() pathGetSetter {
func accessMetricAggTemporality() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
metric := ctx.(metricTransformContext).GetMetric()
metric := ctx.(MetricTransformContext).GetMetric()
switch metric.DataType() {
case pmetric.MetricDataTypeSum:
return int64(metric.Sum().AggregationTemporality())
Expand All @@ -354,7 +354,7 @@ func accessMetricAggTemporality() pathGetSetter {
},
setter: func(ctx tql.TransformContext, val interface{}) {
if newAggTemporality, ok := val.(int64); ok {
metric := ctx.(metricTransformContext).GetMetric()
metric := ctx.(MetricTransformContext).GetMetric()
switch metric.DataType() {
case pmetric.MetricDataTypeSum:
metric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporality(newAggTemporality))
Expand All @@ -371,7 +371,7 @@ func accessMetricAggTemporality() pathGetSetter {
func accessMetricIsMonotonic() pathGetSetter {
return pathGetSetter{
getter: func(ctx tql.TransformContext) interface{} {
metric := ctx.(metricTransformContext).GetMetric()
metric := ctx.(MetricTransformContext).GetMetric()
switch metric.DataType() {
case pmetric.MetricDataTypeSum:
return metric.Sum().IsMonotonic()
Expand All @@ -380,7 +380,7 @@ func accessMetricIsMonotonic() pathGetSetter {
},
setter: func(ctx tql.TransformContext, val interface{}) {
if newIsMonotonic, ok := val.(bool); ok {
metric := ctx.(metricTransformContext).GetMetric()
metric := ctx.(MetricTransformContext).GetMetric()
switch metric.DataType() {
case pmetric.MetricDataTypeSum:
metric.Sum().SetIsMonotonic(newIsMonotonic)
Expand Down
50 changes: 25 additions & 25 deletions pkg/telemetryquerylanguage/contexts/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ func Test_newPathGetSetter_NumberDataPoint(t *testing.T) {

numberDataPoint := createNumberDataPointTelemetry(tt.valueType)

ctx := metricTransformContext{
dataPoint: numberDataPoint,
metric: pmetric.NewMetric(),
il: pcommon.NewInstrumentationScope(),
resource: pcommon.NewResource(),
ctx := MetricTransformContext{
DataPoint: numberDataPoint,
Metric: pmetric.NewMetric(),
InstrumentationScope: pcommon.NewInstrumentationScope(),
Resource: pcommon.NewResource(),
}

got := accessor.Get(ctx)
Expand Down Expand Up @@ -628,11 +628,11 @@ func Test_newPathGetSetter_HistogramDataPoint(t *testing.T) {

numberDataPoint := createHistogramDataPointTelemetry()

ctx := metricTransformContext{
dataPoint: numberDataPoint,
metric: pmetric.NewMetric(),
il: pcommon.NewInstrumentationScope(),
resource: pcommon.NewResource(),
ctx := MetricTransformContext{
DataPoint: numberDataPoint,
Metric: pmetric.NewMetric(),
InstrumentationScope: pcommon.NewInstrumentationScope(),
Resource: pcommon.NewResource(),
}

got := accessor.Get(ctx)
Expand Down Expand Up @@ -1056,11 +1056,11 @@ func Test_newPathGetSetter_ExpoHistogramDataPoint(t *testing.T) {

numberDataPoint := createExpoHistogramDataPointTelemetry()

ctx := metricTransformContext{
dataPoint: numberDataPoint,
metric: pmetric.NewMetric(),
il: pcommon.NewInstrumentationScope(),
resource: pcommon.NewResource(),
ctx := MetricTransformContext{
DataPoint: numberDataPoint,
Metric: pmetric.NewMetric(),
InstrumentationScope: pcommon.NewInstrumentationScope(),
Resource: pcommon.NewResource(),
}

got := accessor.Get(ctx)
Expand Down Expand Up @@ -1369,11 +1369,11 @@ func Test_newPathGetSetter_SummaryDataPoint(t *testing.T) {

numberDataPoint := createSummaryDataPointTelemetry()

ctx := metricTransformContext{
dataPoint: numberDataPoint,
metric: pmetric.NewMetric(),
il: pcommon.NewInstrumentationScope(),
resource: pcommon.NewResource(),
ctx := MetricTransformContext{
DataPoint: numberDataPoint,
Metric: pmetric.NewMetric(),
InstrumentationScope: pcommon.NewInstrumentationScope(),
Resource: pcommon.NewResource(),
}

got := accessor.Get(ctx)
Expand Down Expand Up @@ -1565,11 +1565,11 @@ func Test_newPathGetSetter_Metric(t *testing.T) {

metric := createMetricTelemetry()

ctx := metricTransformContext{
dataPoint: pmetric.NewNumberDataPoint(),
metric: metric,
il: pcommon.NewInstrumentationScope(),
resource: pcommon.NewResource(),
ctx := MetricTransformContext{
DataPoint: pmetric.NewNumberDataPoint(),
Metric: metric,
InstrumentationScope: pcommon.NewInstrumentationScope(),
Resource: pcommon.NewResource(),
}

got := accessor.Get(ctx)
Expand Down
20 changes: 10 additions & 10 deletions pkg/telemetryquerylanguage/contexts/traces/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tql"
)

type spanTransformContext struct {
span ptrace.Span
il pcommon.InstrumentationScope
resource pcommon.Resource
type SpanTransformContext struct {
Span ptrace.Span
InstrumentationScope pcommon.InstrumentationScope
Resource pcommon.Resource
}

func (ctx spanTransformContext) GetItem() interface{} {
return ctx.span
func (ctx SpanTransformContext) GetItem() interface{} {
return ctx.Span
}

func (ctx spanTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.il
func (ctx SpanTransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
return ctx.InstrumentationScope
}

func (ctx spanTransformContext) GetResource() pcommon.Resource {
return ctx.resource
func (ctx SpanTransformContext) GetResource() pcommon.Resource {
return ctx.Resource
}

// pathGetSetter is a getSetter which has been resolved using a path expression provided by a user.
Expand Down
16 changes: 8 additions & 8 deletions pkg/telemetryquerylanguage/contexts/traces/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,17 @@ func Test_newPathGetSetter(t *testing.T) {

span, il, resource := createTelemetry()

got := accessor.Get(spanTransformContext{
span: span,
il: il,
resource: resource,
got := accessor.Get(SpanTransformContext{
Span: span,
InstrumentationScope: il,
Resource: resource,
})
assert.Equal(t, tt.orig, got)

accessor.Set(spanTransformContext{
span: span,
il: il,
resource: resource,
accessor.Set(SpanTransformContext{
Span: span,
InstrumentationScope: il,
Resource: resource,
}, tt.newVal)

exSpan, exIl, exRes := createTelemetry()
Expand Down

0 comments on commit 357dcdc

Please sign in to comment.