-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from jukylin/add_zipkin_header
Add zipkin header
- Loading branch information
Showing
15 changed files
with
522 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; | ||
|
||
use Jaeger\Config; | ||
use OpenTracing\Formats; | ||
use GuzzleHttp\Client; | ||
|
||
$http = new swoole_http_server("0.0.0.0", 8000); | ||
$http->on('request', function ($request, $response) { | ||
unset($_SERVER['argv']); | ||
$config = Config::getInstance(); | ||
$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN; | ||
|
||
//init server span start | ||
$tracer = $config->initTrace('Istio', 'jaeger-agent.istio-system:6831'); | ||
$spanContext = $tracer->extract(Formats\TEXT_MAP, $request->header); | ||
|
||
$serverSpan = $tracer->startSpan('Istio1', ['child_of' => $spanContext]); | ||
$tracer->inject($serverSpan->getContext(), Formats\TEXT_MAP, $_SERVER); | ||
print_r($_SERVER); | ||
//client span1 start | ||
$clientTrace = $config->initTrace('Istio1 HTTP'); | ||
$injectTarget = []; | ||
$spanContext = $clientTrace->extract(Formats\TEXT_MAP, $_SERVER); | ||
$clientSapn = $clientTrace->startSpan('Istio1', ['child_of' => $spanContext]); | ||
$clientTrace->inject($clientSapn->spanContext, Formats\TEXT_MAP, $injectTarget); | ||
|
||
$client = new Client(); | ||
$clientSapn->setTags(["http.url" => "Istio2:8001"]); | ||
$res = $client->request('GET', 'Istio2:8001' ,['headers' => $injectTarget]); | ||
$clientSapn->setTags(["http.status_code" => $res->getStatusCode()]); | ||
//client span1 end | ||
|
||
//server span end | ||
$serverSpan->finish(); | ||
//trace flush | ||
$config->flush(); | ||
|
||
$response->end("Hello Istio1"); | ||
}); | ||
$http->start(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; | ||
|
||
use Jaeger\Config; | ||
use OpenTracing\Formats; | ||
|
||
$http = new swoole_http_server("0.0.0.0", 8001); | ||
$http->on('request', function ($request, $response) { | ||
unset($_SERVER['argv']); | ||
$config = Config::getInstance(); | ||
$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN; | ||
|
||
//init server span start | ||
$tracer = $config->initTrace('Istio', 'jaeger-agent.istio-system:6831'); | ||
$spanContext = $tracer->extract(Formats\TEXT_MAP, $request->header); | ||
$serverSpan = $tracer->startSpan('Istio2', ['child_of' => $spanContext]); | ||
$tracer->inject($serverSpan->getContext(), Formats\TEXT_MAP, $_SERVER); | ||
|
||
//client span1 start | ||
$clientTrace = $config->initTrace('Istio2 HTTP'); | ||
$injectTarget = []; | ||
$spanContext = $clientTrace->extract(Formats\TEXT_MAP, $_SERVER); | ||
$clientSapn = $clientTrace->startSpan('Istio2', ['child_of' => $spanContext]); | ||
$clientTrace->inject($clientSapn->spanContext, Formats\TEXT_MAP, $injectTarget); | ||
|
||
$client = new \GuzzleHttp\Client(); | ||
$clientSapn->setTags(["http.url" => "Istio3:8002"]); | ||
$res = $client->request('GET', 'Istio3:8002', ['headers' => $injectTarget]); | ||
$clientSapn->setTags(["http.status_code" => $res->getStatusCode()]); | ||
//client span1 end | ||
|
||
//server span end | ||
$serverSpan->finish(); | ||
//trace flush | ||
$config->flush(); | ||
|
||
$response->end("Hello Istio2"); | ||
}); | ||
$http->start(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; | ||
|
||
use Jaeger\Config; | ||
use OpenTracing\Formats; | ||
|
||
$http = new swoole_http_server("0.0.0.0", 8002); | ||
$http->on('request', function ($request, $response) { | ||
unset($_SERVER['argv']); | ||
$config = Config::getInstance(); | ||
$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN; | ||
|
||
//init server span start | ||
$tracer = $config->initTrace('Istio', 'jaeger-agent.istio-system:6831'); | ||
|
||
$spanContext = $tracer->extract(Formats\TEXT_MAP, $request->header); | ||
|
||
$serverSpan = $tracer->startSpan('Istio3', ['child_of' => $spanContext]); | ||
$tracer->inject($serverSpan->getContext(), Formats\TEXT_MAP, $_SERVER); | ||
|
||
//client span1 start | ||
$clientTrace = $config->initTrace('Istio3 Bus'); | ||
$spanContext = $clientTrace->extract(Formats\TEXT_MAP, $_SERVER); | ||
$clientSapn = $clientTrace->startSpan('Istio3', ['child_of' => $spanContext]); | ||
|
||
$sum = 0; | ||
for($i = 0; $i < 10; $i++){ | ||
$sum += $i; | ||
} | ||
$clientSapn->log(['message' => 'result:'.$sum]); | ||
$clientSapn->finish(); | ||
|
||
//client span1 end | ||
|
||
//server span end | ||
$serverSpan->finish(); | ||
//trace flush | ||
$config->flush(); | ||
|
||
$response->end("Hello Istio3"); | ||
}); | ||
$http->start(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
# Just for testing | ||
|
||
## Bring up the application containers | ||
``` | ||
kubectl apply -f <(istioctl kube-inject -f istioctl kube-inject -f ./istio.yaml > istio-inject.yaml) | ||
``` | ||
|
||
## Define the ingress gateway for the application | ||
|
||
``` | ||
kubectl apply -f istio-gateway.yaml | ||
``` | ||
|
||
## Access the istio service using curl | ||
|
||
``` | ||
curl -I http://${GATEWAY_URL}/istio1 | ||
``` | ||
|
||
## Check the result in Browser | ||
|
||
``` | ||
kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 16686:16686 & | ||
http://localhost:16686 | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Gateway | ||
metadata: | ||
name: istio-gateway | ||
spec: | ||
selector: | ||
istio: ingressgateway # use istio default controller | ||
servers: | ||
- port: | ||
number: 80 | ||
name: http | ||
protocol: HTTP | ||
hosts: | ||
- "*" | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: istio1 | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- istio-gateway | ||
http: | ||
- match: | ||
- uri: | ||
exact: /istio1 | ||
route: | ||
- destination: | ||
host: istio1 | ||
port: | ||
number: 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
################################################################################################## | ||
# Details service | ||
################################################################################################## | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: istio1 | ||
labels: | ||
app: istio1 | ||
spec: | ||
ports: | ||
- port: 8000 | ||
name: http | ||
selector: | ||
app: istio1 | ||
# type : NodePort | ||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: istio1 | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: istio1 | ||
version: v1 | ||
spec: | ||
containers: | ||
- name: istio1 | ||
image: registry.cn-shenzhen.aliyuncs.com/jukylin/php_swoole:v10 | ||
imagePullPolicy: IfNotPresent | ||
command: ["php"] | ||
args: ["/jukylin/jaeger-php/example/Istio1.php"] | ||
ports: | ||
- containerPort: 8000 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: istio2 | ||
labels: | ||
app: istio2 | ||
spec: | ||
ports: | ||
- port: 8001 | ||
name: http | ||
selector: | ||
app: istio2 | ||
# type : NodePort | ||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: istio2 | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: istio2 | ||
version: v1 | ||
spec: | ||
containers: | ||
- name: istio2 | ||
image: registry.cn-shenzhen.aliyuncs.com/jukylin/php_swoole:v10 | ||
imagePullPolicy: IfNotPresent | ||
command: ["php"] | ||
args: ["/jukylin/jaeger-php/example/Istio2.php"] | ||
ports: | ||
- containerPort: 8001 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: istio3 | ||
labels: | ||
app: istio3 | ||
spec: | ||
ports: | ||
- port: 8002 | ||
name: http | ||
selector: | ||
app: istio3 | ||
# type : NodePort | ||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: istio3 | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: istio3 | ||
version: v1 | ||
spec: | ||
containers: | ||
- name: istio3 | ||
image: registry.cn-shenzhen.aliyuncs.com/jukylin/php_swoole:v10 | ||
imagePullPolicy: IfNotPresent | ||
command: ["php"] | ||
args: ["/jukylin/jaeger-php/example/Istio3.php"] | ||
ports: | ||
- containerPort: 8002 | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.