0f6906942f5259246f3552bdb208348d28521a47
[cps.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2024 Nordix Foundation
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.config
22
23 import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter
24 import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
25 import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler
26 import org.spockframework.spring.SpringBean
27 import org.springframework.boot.actuate.autoconfigure.observation.ObservationRegistryCustomizer
28 import spock.lang.Shared
29 import spock.lang.Specification
30
31 class OpenTelemetryConfigSpec extends Specification{
32
33     @Shared
34     @SpringBean
35     OpenTelemetryConfig openTelemetryConfig = new OpenTelemetryConfig()
36
37     def setupSpec() {
38         openTelemetryConfig.tracingExporterEndpointUrl="http://tracingExporterEndpointUrl"
39         openTelemetryConfig.jaegerRemoteSamplerUrl="http://jaegerremotesamplerurl"
40         openTelemetryConfig.serviceId ="cps-application"
41     }
42
43     def 'OpenTelemetryConfig Construction.'() {
44         expect: 'the system can create an instance'
45         new OpenTelemetryConfig() != null
46     }
47
48     def  'OTLP Exporter creation with Grpc protocol'(){
49         when: 'an OTLP exporter is created'
50             def result = openTelemetryConfig.createOtlpExporterGrpc()
51         then: 'an OTLP Exporter is created'
52             assert result instanceof OtlpGrpcSpanExporter
53     }
54
55     def  'OTLP Exporter creation with HTTP protocol'(){
56         when: 'an OTLP exporter is created'
57             def result = openTelemetryConfig.createOtlpExporterHttp()
58         then: 'an OTLP Exporter is created'
59             assert result instanceof OtlpHttpSpanExporter
60         and:
61             assert result.builder.endpoint=="http://tracingExporterEndpointUrl"
62     }
63
64     def  'Jaeger Remote Sampler Creation'(){
65         when: 'an OTLP exporter is created'
66             def result = openTelemetryConfig.createJaegerRemoteSampler()
67         then: 'an OTLP Exporter is created'
68             assert result instanceof JaegerRemoteSampler
69         and:
70             assert result.delegate.type=="remoteSampling"
71         and:
72             assert result.delegate.url.toString().startsWith("http://jaegerremotesamplerurl")
73     }
74
75     def  'Skipping Acutator endpoints'(){
76         when: 'an OTLP exporter is created'
77             def result = openTelemetryConfig.skipActuatorEndpointsFromObservation()
78         then: 'an OTLP Exporter is created'
79             assert result instanceof ObservationRegistryCustomizer
80     }
81 }