open-traffic-generator / openapiart

OpenAPI artifact generator
MIT License
6 stars 4 forks source link

Otlp support #422

Open Vibaswan opened 1 year ago

Vibaswan commented 1 year ago

This PR is currently work in progress for the OTLP support in openapiart

Fixes #434 Fixes #435

First Step taken is to implement telemetry in go-snappi

Things done till now

Things to be done

Sample Scripts.

Note: FYI the sample scripts were run from openapiart to otg-hw just to showcase the use-cases, as openapiart has its own sample model the set config error out

No custom Span provided by the user

func TestTelemetry(t *testing.T) {
    api := gosnappi.NewApi()
    api.NewGrpcTransport().SetLocation("10.66.47.117:5001")

        // start basically creates the trace provider which is a pipe keeping hold of the telemetry data
        tel, err := api.Telemetry().WithExporterEndPoint("10.66.47.117:4318").Start()
    if err != nil {
        t.Log(err)
    }
        // this is a mandatory step in the script if using telemetry, as it will stop the tracing and shut down the tracer
        // cannot be called automatically from the SDK as we don't know the when the user wants to stop it 
    defer tel.Stop()
    // NewFullyPopulatedPrefixConfig is just a dummy func here , actual config will be built here
        config := NewFullyPopulatedPrefixConfig(api)
    resp, err := api.SetConfig(config)
}

Python Sample script:

import snappi

api = snappi.api(location="10.66.47.117:5001", transport="grpc", verify=False,
                 telemetry_collector_endpoint="http://10.66.47.117:4318/v1/traces")

with api.tracer().start_as_current_span("test-telemetry"):
    # perform api calls for rest of the script

# scope of span ends
print("test passed")

Note: nomenclature for the functions are not finalized

Jaeger visualization

image

When custom Span is added by the user

func TestTelemetry(t *testing.T) {
    api := gosnappi.NewApi()
    api.NewGrpcTransport().SetLocation("10.66.47.117:5001")
    tel, err := api.Telemetry().WithExporterEndPoint("10.66.47.117:4318").StartTracing()
    if err != nil {
        t.Log(err)
    }
    defer tel.StopTracing()

        // adding custom span from the script
    ctx, span := tel.NewSpan(context.Background(), "test-telemetry")
    // generally if we are adding a span we want the SDK to generate child spans for this custom span.
    // so that its easier to visualize.
    // That's why we need to set the root context so that the SDK can treat it as parent and generate the rest of the child spans 
        tel.WithRootContext(ctx)
    defer tel.CloseSpan(span)

        // NewFullyPopulatedPrefixConfig is just a dummy func here , actual config will be built here
    config := NewFullyPopulatedPrefixConfig(api)
    resp, err := api.SetConfig(config)
}

Jaeger visualization

image

Current Challenges

rudranil-das commented 1 year ago

Adding some ToDos (all of which might not be entirely doable through snappi, but keeping a note as end goal)

  1. Need to find a way to propagate test-case PASS/FAIL info as part of span, preferably not requiring to update individual TCs. (this is a priority for controller CI TCs)
  2. Ability to add some common attributes in all spans from an application.
  3. Ability to dump all spans from an application in a local file (this ability could be optional and application may want to trigger it through a flag/option)