Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit d1512ab

Browse files
authored
OpenCensus Stats implementation (#220)
Initial version of OpenCensus Stats and Tags API Also: - PHP 7.3 testing & support - Fix issue with test filenames and phpize --clean (don't allow .php in ext dir) - DaemonClient (Go) for transporting OpenCensus data from PHP to OpenCensus Service - Extension update to include low level daemon client offloading data transmission from request path - Removes support for PHP 5.6 and PHP 7.0 - Fixed Symfony test - Fixed Wordpress test (they have a new and different default theme generating different calls) - Added Dockerfile for Daemon Service - Added Dockerfile for OpenCensus enabled PHP7.3-Apache (for demo/testing purposes)
1 parent 31dc521 commit d1512ab

File tree

95 files changed

+5624
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+5624
-347
lines changed

.circleci/config.yml

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,6 @@ unit-config: &unit-config
7777
7878
version: 2
7979
jobs:
80-
php56:
81-
<<: *unit-config
82-
docker:
83-
- image: circleci/php:5.6-node
84-
environment:
85-
RUN_EXTENSION_TESTS: 0
86-
SUDO_CMD: "sudo"
87-
88-
php56-zts:
89-
<<: *unit-config
90-
docker:
91-
- image: circleci/php:5.6-zts-node
92-
environment:
93-
RUN_EXTENSION_TESTS: 0
94-
SUDO_CMD: "sudo"
95-
96-
php70:
97-
<<: *unit-config
98-
docker:
99-
- image: circleci/php:7.0-node
100-
101-
php70-zts:
102-
<<: *unit-config
103-
docker:
104-
- image: circleci/php:7.0-zts-node
105-
10680
php71:
10781
<<: *unit-config
10882
docker:
@@ -123,15 +97,15 @@ jobs:
12397
docker:
12498
- image: circleci/php:7.2-zts-node
12599

126-
php70-32bit:
100+
php73:
127101
<<: *unit-config
128102
docker:
129-
- image: gcr.io/php-stackdriver/php70-32bit
130-
environment:
131-
TEST_PHP_ARGS: -q
132-
REPORT_EXIT_STATUS: 1
133-
RUN_EXTENSION_TESTS: 1
134-
SUDO_CMD: ""
103+
- image: circleci/php:7.3-node
104+
105+
php73-zts:
106+
<<: *unit-config
107+
docker:
108+
- image: circleci/php:7.3-zts-node
135109

136110
php71-32bit:
137111
<<: *unit-config
@@ -246,15 +220,12 @@ workflows:
246220
version: 2
247221
units:
248222
jobs:
249-
- php56
250-
- php56-zts
251-
- php70
252-
- php70-zts
253223
- php71
254224
- php71-zts
255225
- php72
256226
- php72-zts
257-
- php70-32bit
227+
- php73
228+
- php73-zts
258229
- php71-32bit
259230
- php71-debug
260231
- integration

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# OS X
22
.DS_Store
33

4-
# VSCode
4+
# VSCode and other IDE's
55
.vscode/
6+
.idea/
67

78
# Composer
89
build/

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
{
88
"name": "Jeff Ching",
99
"email": "chingor@google.com"
10+
},
11+
{
12+
"name": "Bas van Beek",
13+
"email": "bas.vanbeek@gmail.com"
1014
}
1115
],
1216
"minimum-stability": "stable",
1317
"require": {
14-
"php": ">=5.6",
18+
"php": ">=7.1",
1519
"ramsey/uuid": "~3",
1620
"psr/log": "^1.0",
1721
"psr/cache": "^1.0",

daemon/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# build oc-daemon binary
3+
#
4+
5+
FROM golang:alpine as builder
6+
ENV GOPATH /go
7+
8+
RUN apk update && apk add --no-cache git ca-certificates tzdata make && update-ca-certificates
9+
10+
RUN adduser -D -g '' opencensus
11+
12+
COPY . $GOPATH/src/github.com/census-instrumentation/opencensus-php/daemon
13+
WORKDIR $GOPATH/src/github.com/census-instrumentation/opencensus-php/daemon
14+
15+
RUN mkdir /newtmp && chown opencensus /newtmp && chmod 777 /newtmp
16+
17+
RUN CGO_ENABLED=0 make build-linux
18+
19+
#
20+
# build image from scratch
21+
#
22+
23+
FROM scratch
24+
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
25+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
26+
COPY --from=builder /etc/passwd /etc/passwd
27+
COPY --from=builder /etc/group /etc/group
28+
COPY --from=builder /go/src/github.com/census-instrumentation/opencensus-php/daemon/build/oc-daemon-linux /usr/bin/oc-daemon
29+
COPY --chown=opencensus:opencensus --from=builder /newtmp /tmp
30+
31+
VOLUME /tmp
32+
33+
USER opencensus
34+
35+
ENTRYPOINT ["/usr/bin/oc-daemon"]

daemon/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BUILD := $(shell git describe --long --tags)
2+
BUILD_DATE := $(shell date -u +'%Y-%m-%d %H:%M:%S')
3+
4+
ifeq ($(BUILD),)
5+
BUILD := "v0.0.0"
6+
endif
7+
8+
.PHONY: test
9+
test:
10+
go test -v -race -cover ./...
11+
12+
.PHONY: lint
13+
lint:
14+
golint ./...
15+
16+
.PHONY: vet
17+
vet:
18+
go vet ./...
19+
20+
build: build-linux build-darwin build-windows
21+
22+
build-linux:
23+
GO111MODULE=on GOOS=linux GOARCH=amd64 go build -i -ldflags "-X \"main.buildVersion=${BUILD} (Linux)\" -X \"main.buildDate=${BUILD_DATE}\"" -o build/oc-daemon-linux ./cmd
24+
25+
build-darwin:
26+
GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -i -ldflags "-X \"main.buildVersion=${BUILD} (OS X)\" -X \"main.buildDate=${BUILD_DATE}\"" -o build/oc-daemon-osx ./cmd
27+
28+
build-windows:
29+
GO111MODULE=on GOOS=windows GOARCH=amd64 go build -i -ldflags "-X \"main.buildVersion=${BUILD} (Windows)\" -X \"main.buildDate=${BUILD_DATE}\"" -o build/oc-daemon.exe ./cmd
30+
31+
docker:
32+
docker build --rm --no-cache -f Dockerfile -t oc-daemon .
33+
34+
clean:
35+
@rm -rf build
36+
37+
.PHONY: all
38+
all: clean vet lint test build

daemon/README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# OpenCensus PHP Daemon Service
2+
3+
The Daemon service allows the OpenCensus PHP library to export stats and traces
4+
over a local unix socket or windows named pipe. The Daemon will then take care
5+
of transporting the information to the OpenCensus Agent over gRPC.
6+
7+
By using the Daemon in between the OpenCensus PHP library and OpenCensus Agent
8+
we avoid the need of injecting the gRPC extension into PHP, even making it
9+
possible to run OpenCensus without the need of installing any extension.
10+
11+
## Daemon Protocol
12+
13+
Communication between OpenCensus PHP and OpenCensus PHP Daemon service is
14+
handled by using a simple protocol. The protocol is designed to expect partial
15+
message delivery allowing such a message to be discarded and proceed to ingest
16+
the next message. This situation can occur when using the PHP user land
17+
implementation of the Daemon client as it uses non blocking sockets with a
18+
settable maximum message delivery time to not hold up the PHP request critical
19+
path.
20+
21+
A protocol message consists of a header and the message payload.
22+
23+
All number representations (UVarint, Float64, padded Float32, Integer) are sent
24+
in big endian (network) byte order.
25+
26+
### Protocol header
27+
28+
| name | type | size | comment
29+
|----------------|---------|------:|---------
30+
| SOM | Bytes | 4 | Start of message "\x00\x00\x00\x00"
31+
| Message Type | Byte | 1 | Message Type
32+
| Sequence Nr. | UVarInt | 1-10 |
33+
| Process ID | UVarInt | 1-10 |
34+
| Thread ID | UVarInt | 1-10 | Will be 0 for non ZTS deployments
35+
| StartTime | Float* | 8 | Unix timestamp with fraction: Float64 or padded Float32 (`\x00\x00 + Float32 + \x00\x00`)
36+
| Message Length | UVarInt | 1-10 | **TODO:** identify a maximum allowed message length. This will most likely be dictated by Span exports.
37+
38+
**Note:** PHP can't guarantee the size of a Float when exporting it out. It will
39+
either be 64 bit or 32 bit depending on the platform. If StartTime is padded
40+
with `\x00\x00` on both sides we know that all exported floats will be of 32 bit
41+
length. If StartTime is a 64bit float, all remaining Float values will be
42+
exported as 64 bit.
43+
44+
By use of UVarInt we have a variable length Header. This allows the header to be
45+
as small as 17 bytes in the most optimistic circumstances and as large as 53 in
46+
the most pessimistic ones.
47+
48+
### Data Types
49+
50+
Our messages allow for the following data types and their encoding:
51+
52+
#### Byte
53+
Single unsigned byte holding value between 0 and 255.
54+
55+
#### Float
56+
Depending on the PHP runtime a float value will be either 64 or 32 bit in
57+
resolution. All floats are big endian (network) byte order encoded. To identify
58+
the size of the float, the Daemon implementation inspects the StartTime field in
59+
the header. If this field is `\x00\x00` padded on both sides, we're dealing with
60+
32 bit floats.
61+
62+
#### String
63+
Strings are prefixed by a UVarInt indicating string length immediately followed
64+
by the unterminated binary string payload. Empty strings are allowed.
65+
66+
#### Array
67+
Arrays are prefixed by a UVarInt indicating the array item count immediately
68+
followed by the array items. Empty arrays are allowed.
69+
70+
### Protocol message types
71+
72+
The following message types and their contents have been defined.
73+
74+
#### MSG_PROC_INIT
75+
**Message Type: 1**
76+
77+
Sent to the Daemon when a new PHP Process spawns. (only sent if using the
78+
OpenCensus Extension).
79+
80+
**TODO**: payload to be determined
81+
82+
#### MSG_PROC_SHUTDOWN
83+
**Message Type: 2**
84+
85+
Sent to the Daemon when a PHP Process is shut down. (only sent if using the
86+
OpenCensus Extension).
87+
88+
**TODO**: payload to be determined
89+
90+
#### MSG_REQ_INIT
91+
**Message Type: 3**
92+
93+
Sent to the Daemon when a new PHP Request is received.
94+
95+
| field | type | comment
96+
|--------------------|---------|---------
97+
| Protocol Version | Byte | Daemon Protocol Version (currently 1 only)
98+
| PHP Version | String |
99+
| Zend Version | String |
100+
101+
102+
#### MSG_REQ_SHUTDOWN
103+
**Message Type: 4**
104+
105+
Sent to the Daemon when a PHP Request ends.
106+
107+
| field | type | comment
108+
|-------|------|---------
109+
| - | - | no message payload
110+
111+
#### MSG_TRACE_EXPORT
112+
**Message Type: 20**
113+
114+
A collection of Spans ready to be exported.
115+
116+
**TODO:** Currently uses a JSON encoded array of spans. Span payload is
117+
subject to change.
118+
119+
#### MSG_MEASURE_CREATE
120+
**Message Type: 40**
121+
122+
Measure Create request.
123+
124+
| field | type | comment
125+
|--------------------|---------|---------
126+
| MeasureType | Byte | 1 = IntMeasure, 2 = FloatMeasure
127+
| Name | String |
128+
| Description | String |
129+
| Unit | String |
130+
131+
#### MSG_VIEW_REPORTING_PERIOD
132+
**Message Type: 41**
133+
134+
Reporting Period adjustment request.
135+
136+
| field | type | comment
137+
|--------------------|---------|---------
138+
| Interval | Float | Interval in seconds
139+
140+
#### MSG_VIEW_REGISTER
141+
**Message Type: 42**
142+
143+
Register View request.
144+
145+
| field | type | comment
146+
|--------------------|-------------------|---------
147+
| Views | Array of **View** | Array of Views to Register.
148+
149+
View Type:
150+
151+
| field | type | comment
152+
|--------------------|-----------------|---------
153+
| View Name | String |
154+
| View Description | String |
155+
| Tag Keys | Array of String | Array of TagKey values.
156+
| Measure Name | String |
157+
| Aggregation Type | Byte | 0 = None, 1 = Count, 2 = Sum, 3 = Distribution, 4 = Last Value
158+
| Bucket Boundaries* | Array of Float | Only sent for the Distribution aggregation type
159+
160+
161+
#### MSG_VIEW_UNREGISTER
162+
**Message Type: 43**
163+
164+
Unregister View request.
165+
166+
| field | type | comment
167+
|--------------------|-----------------|---------
168+
| View Names | Array of String | Array holding names of Views to Unregister
169+
170+
#### MSG_STATS_RECORD
171+
**Message Type: 44**
172+
173+
Stats Record request.
174+
175+
| field | type | comment
176+
|--------------------|--------------------------|---------
177+
| Measurements | Array of **Measurement** | Measurements to record
178+
| Tags | Array of **KeyValue** | Tag kv pairs
179+
| Attachments | Array of **KeyValue** | Exemplar attachment kv pairs
180+
181+
Measurement Type:
182+
183+
| field | type | comment
184+
|--------------|--------|---------
185+
| Name | String |
186+
| Measure Type | Byte | 1 = IntMeasure, 2 = FloatMeasure
187+
| Value | Float | Value is always transported as Float
188+
189+
KeyValue Type:
190+
191+
| field | type | comment
192+
|-------|--------|---------
193+
| Key | String |
194+
| Value | String |

0 commit comments

Comments
 (0)