diff --git a/.github/workflows/e2e.php.yaml b/.github/workflows/e2e.php.yaml new file mode 100644 index 000000000..383cad82c --- /dev/null +++ b/.github/workflows/e2e.php.yaml @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: E2E + +on: + pull_request: + push: + branches: + - master + tags: + - 'v*' + +env: + SKIP_TEST: true + SW_AGENT_JDK_VERSION: 8 + +jobs: + PHPAgent: + name: PHP + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: checkout submodules + shell: bash + run: | + git submodule sync --recursive + git -c protocol.version=2 submodule update --init --force --recursive --depth=1 + - name: Compile and Build + run: make docker + - name: Copy dist package + run: cp -R dist test/e2e/ + - name: PHP + run: ./mvnw --batch-mode -f test/e2e/pom.xml -am -DfailIfNoTests=false verify -Dit.test=org.apache.skywalking.e2e.PHPE2E + - uses: actions/upload-artifact@v1 + if: failure() + with: + name: logs + path: logs diff --git a/test/e2e/e2e-test/docker/php/docker-compose.yml b/test/e2e/e2e-test/docker/php/docker-compose.yml new file mode 100644 index 000000000..8b8bd388f --- /dev/null +++ b/test/e2e/e2e-test/docker/php/docker-compose.yml @@ -0,0 +1,82 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '2.1' + +services: + oap: + image: skywalking/oap:latest + expose: + - 11800 + - 12800 + networks: + - e2e + restart: on-failure + healthcheck: + test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/11800"] + interval: 5s + timeout: 60s + retries: 120 + + php-shadow: + image: skyapm/skywalking-php:v3.2.8 + networks: + - e2e + expose: + - 8080 + environment: + - SW_AGENT_COLLECTOR_BACKEND_SERVICES=oap:11800 + depends_on: + oap: + condition: service_healthy + volumes: + - ./index.php:/var/www/html/index.php + - ./php-shadow.ini:/usr/local/etc/php/conf.d/ext-skywalking.ini + + php: + image: skyapm/skywalking-php:v3.2.8 + networks: + - e2e + expose: + - 8080 + environment: + - SW_AGENT_COLLECTOR_BACKEND_SERVICES=oap:11800 + depends_on: + php-shadow: + condition: service_started + oap: + condition: service_healthy + volumes: + - ./index.php:/var/www/html/index.php + - ./php.ini:/usr/local/etc/php/conf.d/ext-skywalking.ini + + ui: + image: skywalking/ui:latest + expose: + - 8080 + networks: + - e2e + environment: + - SW_OAP_ADDRESS=oap:12800 + depends_on: + php: + condition: service_started + php-shadow: + condition: service_started + oap: + condition: service_healthy + +networks: + e2e: \ No newline at end of file diff --git a/test/e2e/e2e-test/docker/php/index.php b/test/e2e/e2e-test/docker/php/index.php new file mode 100644 index 000000000..330e60fdf --- /dev/null +++ b/test/e2e/e2e-test/docker/php/index.php @@ -0,0 +1,25 @@ + justForSideEffects; + + @SuppressWarnings("unused") + @ContainerHostAndPort(name = "ui", port = 8080) + private HostAndPort swWebappHostPort; + + @SuppressWarnings("unused") + @ContainerHostAndPort(name = "php", port = 8080) + private HostAndPort phpHostPort; + + @SuppressWarnings("unused") + @ContainerHostAndPort(name = "php-shadow", port = 8080) + private HostAndPort phpShadowHostPort; + + private final String shadowServiceName = "php-shadow"; + + @BeforeAll + public void setUp() throws Exception { + URL url = new URL("http", phpHostPort.host(), phpHostPort.port(), "/init"); + restTemplate.getForObject(url.toURI(), String.class); + Thread.sleep(1000); + url = new URL("http", phpShadowHostPort.host(), phpShadowHostPort.port(), "/init-shadow"); + restTemplate.getForObject(url.toURI(), String.class); + Thread.sleep(1000); + queryClient(swWebappHostPort); + + trafficController(phpHostPort, "/php/info"); + } + + @AfterAll + public void tearDown() { + trafficController.stop(); + } + + @RetryableTest + void services() throws Exception { + final List services = graphql.services(new ServicesQuery().start(startTime).end(now())); + + LOGGER.info("services: {}", services); + + load("expected/php/services.yml").as(ServicesMatcher.class).verify(services); + + for (Service service : services) { + LOGGER.info("verifying service instances: {}", service); + + verifyServiceMetrics(service); + + final Instances instances = verifyServiceInstances(service); + + verifyInstancesMetrics(instances); + + final Endpoints endpoints = verifyServiceEndpoints(service); + + verifyEndpointsMetrics(endpoints); + } + } + + @RetryableTest + void traces() throws Exception { + final List traces = graphql.traces(new TracesQuery().start(startTime).end(now()).orderByStartTime()); + + LOGGER.info("traces: {}", traces); + + load("expected/php/traces.yml").as(TracesMatcher.class).verifyLoosely(traces); + } + + @RetryableTest + void topology() throws Exception { + final Topology topology = graphql.topo(new TopoQuery().stepByMinute().start(startTime.minusDays(1)).end(now())); + + LOGGER.info("topology: {}", topology); + + load("expected/php/topo.yml").as(TopoMatcher.class).verify(topology); + + verifyServiceRelationMetrics(topology.getCalls()); + } + + @RetryableTest + void serviceInstances() throws Exception { + + final ServiceInstanceTopology topology = graphql.serviceInstanceTopo( + new ServiceInstanceTopologyQuery().stepByMinute() + .start(startTime.minusDays(1)) + .end(now()) + .clientServiceId("1") + .serverServiceId("2")); + + LOGGER.info("topology: {}", topology); + + load("expected/php/serviceInstanceTopo.yml").as(ServiceInstanceTopologyMatcher.class).verify(topology); + + verifyServiceInstanceRelationMetrics(topology.getCalls()); + } + + private Instances verifyServiceInstances(final Service service) throws Exception { + final Instances instances = graphql.instances( + new InstancesQuery().serviceId(service.getKey()).start(startTime).end(now()) + ); + + LOGGER.info("instances: {} {}", service.getLabel(), instances); + + if (shadowServiceName.equals(service.getLabel())) { + load("expected/php/shadowInstances.yml").as(InstancesMatcher.class).verify(instances); + } else { + load("expected/php/instances.yml").as(InstancesMatcher.class).verify(instances); + } + + return instances; + } + + private Endpoints verifyServiceEndpoints(final Service service) throws Exception { + final Endpoints endpoints = graphql.endpoints(new EndpointQuery().serviceId(service.getKey())); + + LOGGER.info("endpoints: {} {}", service.getLabel(), endpoints); + + if (shadowServiceName.equals(service.getLabel())) { + load("expected/php/shadowEndpoints.yml").as(EndpointsMatcher.class).verify(endpoints); + } else { + load("expected/php/endpoints.yml").as(EndpointsMatcher.class).verify(endpoints); + } + + return endpoints; + } + + private void verifyInstancesMetrics(Instances instances) throws Exception { + for (Instance instance : instances.getInstances()) { + for (String metricsName : ALL_INSTANCE_METRICS) { + LOGGER.info("verifying service instance response time: {}", instance); + final Metrics instanceMetrics = graphql.metrics( + new MetricsQuery().stepByMinute().metricsName(metricsName).id(instance.getKey()) + ); + + LOGGER.info("instance metrics: {}", instanceMetrics); + + final AtLeastOneOfMetricsMatcher instanceRespTimeMatcher = new AtLeastOneOfMetricsMatcher(); + final MetricsValueMatcher greaterThanZero = new MetricsValueMatcher(); + greaterThanZero.setValue("gt 0"); + instanceRespTimeMatcher.setValue(greaterThanZero); + instanceRespTimeMatcher.verify(instanceMetrics); + LOGGER.info("{}: {}", metricsName, instanceMetrics); + } + } + } + + private void verifyEndpointsMetrics(Endpoints endpoints) throws Exception { + for (Endpoint endpoint : endpoints.getEndpoints()) { + if (!endpoint.getLabel().equals("/php/call") || !endpoint.getLabel().equals("/php/info")) { + continue; + } + for (final String metricName : ALL_ENDPOINT_METRICS) { + LOGGER.info("verifying endpoint {}: {}", endpoint, metricName); + + final Metrics metrics = graphql.metrics( + new MetricsQuery().stepByMinute().metricsName(metricName).id(endpoint.getKey()) + ); + + LOGGER.info("metrics: {}", metrics); + + final AtLeastOneOfMetricsMatcher instanceRespTimeMatcher = new AtLeastOneOfMetricsMatcher(); + final MetricsValueMatcher greaterThanZero = new MetricsValueMatcher(); + greaterThanZero.setValue("gt 0"); + instanceRespTimeMatcher.setValue(greaterThanZero); + instanceRespTimeMatcher.verify(metrics); + + LOGGER.info("{}: {}", metricName, metrics); + } + } + } + + private void verifyServiceMetrics(final Service service) throws Exception { + for (String metricName : ALL_SERVICE_METRICS) { + LOGGER.info("verifying service {}, metrics: {}", service, metricName); + final Metrics serviceMetrics = graphql.metrics( + new MetricsQuery().stepByMinute().metricsName(metricName).id(service.getKey()) + ); + LOGGER.info("serviceMetrics: {}", serviceMetrics); + final AtLeastOneOfMetricsMatcher instanceRespTimeMatcher = new AtLeastOneOfMetricsMatcher(); + final MetricsValueMatcher greaterThanZero = new MetricsValueMatcher(); + greaterThanZero.setValue("gt 0"); + instanceRespTimeMatcher.setValue(greaterThanZero); + instanceRespTimeMatcher.verify(serviceMetrics); + LOGGER.info("{}: {}", metricName, serviceMetrics); + } + } + + private void verifyServiceInstanceRelationMetrics(final List calls) throws Exception { + verifyRelationMetrics( + calls, ALL_SERVICE_INSTANCE_RELATION_CLIENT_METRICS, + ALL_SERVICE_INSTANCE_RELATION_SERVER_METRICS + ); + } + + private void verifyServiceRelationMetrics(final List calls) throws Exception { + verifyRelationMetrics(calls, ALL_SERVICE_RELATION_CLIENT_METRICS, ALL_SERVICE_RELATION_SERVER_METRICS); + } + + private void verifyRelationMetrics(final List calls, + final String[] relationClientMetrics, + final String[] relationServerMetrics) throws Exception { + for (Call call : calls) { + for (String detectPoint : call.getDetectPoints()) { + switch (detectPoint) { + case "CLIENT": { + for (String metricName : relationClientMetrics) { + verifyMetrics(graphql, metricName, call.getId(), startTime); + } + break; + } + case "SERVER": { + for (String metricName : relationServerMetrics) { + verifyMetrics(graphql, metricName, call.getId(), startTime); + } + break; + } + } + } + } + } +} diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/endpoints.yml b/test/e2e/e2e-test/src/test/resources/expected/php/endpoints.yml new file mode 100644 index 000000000..73249ee12 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/endpoints.yml @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +endpoints: + - key: not null + label: /php/info + - key: not null + label: /php/call + + + diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/instances.yml b/test/e2e/e2e-test/src/test/resources/expected/php/instances.yml new file mode 100644 index 000000000..83dbceee4 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/instances.yml @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +instances: + - key: 2 + label: not null + attributes: + - name: os_name + value: not null + - name: host_name + value: not null + - name: process_no + value: gt 0 + - name: ipv4s + value: not null diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/serviceInstanceTopo.yml b/test/e2e/e2e-test/src/test/resources/expected/php/serviceInstanceTopo.yml new file mode 100644 index 000000000..238e70a9a --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/serviceInstanceTopo.yml @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +nodes: + - id: 1 + name: User + type: USER + serviceId: 1 + serviceName: User + isReal: false + - id: 2 + name: not null + serviceId: 2 + serviceName: php + type: not null + isReal: true +calls: + - id: 1_2 + source: 1 + detectPoints: + - SERVER + target: 2 diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/services.yml b/test/e2e/e2e-test/src/test/resources/expected/php/services.yml new file mode 100644 index 000000000..d57c2a5e4 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/services.yml @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +services: + - key: gt 0 + label: "php" + - key: gt 0 + label: "php-shadow" \ No newline at end of file diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/shadowEndpoints.yml b/test/e2e/e2e-test/src/test/resources/expected/php/shadowEndpoints.yml new file mode 100644 index 000000000..969d1c233 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/shadowEndpoints.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +endpoints: + - key: not null + label: /php/call + + + diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/shadowInstances.yml b/test/e2e/e2e-test/src/test/resources/expected/php/shadowInstances.yml new file mode 100644 index 000000000..d9af02b59 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/shadowInstances.yml @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +instances: + - key: 3 + label: not null + attributes: + - name: os_name + value: not null + - name: host_name + value: not null + - name: process_no + value: gt 0 + - name: ipv4s + value: not null diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/topo.yml b/test/e2e/e2e-test/src/test/resources/expected/php/topo.yml new file mode 100644 index 000000000..09462de1b --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/topo.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +nodes: + - id: 1 + name: User + type: USER + isReal: false + - id: 2 + name: php + type: HttpClient + isReal: true + - id: 3 + name: php-shadow + type: HttpClient + isReal: true +calls: + - id: 1_2 + source: 1 + detectPoints: + - SERVER + target: 2 + - id: 2_3 + source: 2 + detectPoints: + - CLIENT + - SERVER + target: 3 \ No newline at end of file diff --git a/test/e2e/e2e-test/src/test/resources/expected/php/traces.yml b/test/e2e/e2e-test/src/test/resources/expected/php/traces.yml new file mode 100644 index 000000000..f558c2ec7 --- /dev/null +++ b/test/e2e/e2e-test/src/test/resources/expected/php/traces.yml @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +traces: + - key: not null + endpointNames: + - /php/info + duration: ge 0 + start: gt 0 + isError: false + traceIds: + - not null + - key: not null + endpointNames: + - /php/call + duration: ge 0 + start: gt 0 + isError: false + traceIds: + - not null \ No newline at end of file