From f01d14a504445fb7385b6bb9424f9da342144452 Mon Sep 17 00:00:00 2001 From: Tigran Najaryan Date: Tue, 8 Mar 2022 11:26:28 -0500 Subject: [PATCH] Add TODOs --- processor/schemaprocessor/factory.go | 7 +++++++ processor/schemaprocessor/processor.go | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/processor/schemaprocessor/factory.go b/processor/schemaprocessor/factory.go index 798d91a00902..531176af5d1a 100644 --- a/processor/schemaprocessor/factory.go +++ b/processor/schemaprocessor/factory.go @@ -44,6 +44,9 @@ type factory struct { schemas map[string]*ast.Schema } +// TODO: check if storage extension is available on the Host and use the storage +// as a cache for downloaded schemas. Load cached schemas when the processor is started. + // NewFactory returns a new factory for the schema processor. func NewFactory() component.ProcessorFactory { return newFactoryWithFetcher(downloadSchema) @@ -120,6 +123,10 @@ func downloadSchema(context context.Context, schemaURL string) (*ast.Schema, err schema, err := schemas.Parse(resp.Body) + // TODO: compile schema into a form that makes data transformation more efficient + // todo perform. See for example as an inspiration: + // https://github.com/tigrannajaryan/telemetry-schema/tree/main/schema/compiled + return schema, err } diff --git a/processor/schemaprocessor/processor.go b/processor/schemaprocessor/processor.go index bfa80058d66c..e577c3aa5064 100644 --- a/processor/schemaprocessor/processor.go +++ b/processor/schemaprocessor/processor.go @@ -18,19 +18,38 @@ func newSchemaProcessor(ctx context.Context, factory *factory, cfg *Config) *sch return &schemaProcessor{factory: factory} } -func (a *schemaProcessor) processTraces(_ context.Context, td pdata.Traces) (pdata.Traces, error) { +func (a *schemaProcessor) processTraces(ctx context.Context, td pdata.Traces) (pdata.Traces, error) { rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) resource := rs.Resource() + + resourceSchema, err := a.factory.getSchema(ctx, rs.SchemaUrl()) + if err != nil { + // TODO: what do we do if we can't fetch the schema? + } + // TODO: use resourceSchema to transform the Resource. + // See as an inspiration for example: + // https://github.com/tigrannajaryan/telemetry-schema/blob/main/schema/converter/converter.go + _ = resourceSchema + ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) spans := ils.Spans() library := ils.InstrumentationLibrary() + + libSchema, err := a.factory.getSchema(ctx, ils.SchemaUrl()) + if err != nil { + // TODO: what do we do if we can't fetch the schema? + } + _ = libSchema + for k := 0; k < spans.Len(); k++ { span := spans.At(k) + // TODO: use resourceSchema and libSchema to transform the span. + _ = resource _ = library _ = span