Skip to content

Commit 37f1566

Browse files
authored
Merge pull request #3 from lindig/CP-18272
CP-18272 - add integration tests
2 parents 35d116b + 85747c7 commit 37f1566

23 files changed

+3030
-115
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "parson"]
2-
path = parson
3-
url = https://github.com/kgabis/parson.git

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ matrix:
88
os: linux
99

1010
script:
11-
- make parson
1211
- make
1312
- make test
1413

Makefile

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# vim: set ts=8 sw=8 noet:
22
#
3+
# To run the integration tests you need the ocaml-rrd-transport-devel
4+
# package:
5+
#
6+
# yum install -y ocaml-rrd-transport-devel
37
#
48

59
CC = gcc
@@ -28,9 +32,18 @@ clean:
2832
test: rrdtest rrdclient
2933
./rrdtest
3034
seq 1 10 | ./rrdclient rrdclient.rrd
31-
seq 1 10 \
32-
| while read i; do echo $$i; sleep 1; done \
33-
| ./rrdclient rrdclient.rrd
35+
36+
.PHONY: test-integration
37+
test-integration:
38+
seq 1 10 | while read i; do \
39+
echo $$i | ./rrdclient rrdclient.rrd ;\
40+
rrdreader file --once rrdclient.rrd v2 ;\
41+
done
42+
seq 1 20 | while read i; do \
43+
echo $$i | ./rrdclient rrdclient.rrd ;\
44+
sleep 4 ;\
45+
done & rrdreader file rrdclient.rrd v2 \
46+
|| echo "a final exception Rrd_protocol.No_update is OK"
3447

3548
.PHONY: valgrind
3649
valgrind: rrdtest
@@ -45,12 +58,6 @@ indent: librrd.h librrd.c rrdtest.c
4558
depend: librrd.c rrdtest.c
4659
$(CC) -MM $^
4760

48-
.PHONY: parson
49-
parson:
50-
# git submodule add https://github.com/kgabis/parson.git
51-
git submodule init
52-
git submodule update
53-
5461
%.o: %.c
5562
$(CC) $(CFLAGS) -c -o $@ $<
5663

@@ -91,9 +98,3 @@ parson/parson.o: parson/parson.h
9198
rrdtest.o: parson/parson.h librrd.h
9299
librrd.o: parson/parson.h librrd.h
93100

94-
# OCaml test utility
95-
# You need: yum install -y ocaml-rrd-transport-devel
96-
97-
rrdreader:
98-
cd ocaml; $(OCB) -pkg rrd-transport -tag thread rrdreader.native
99-

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
[![Build Status](https://travis-ci.org/lindig/rrd-client-lib-1.svg?branch=master)](https://travis-ci.org/lindig/rrd-client-lib-1)
2+
[![Build Status](https://travis-ci.org/xapi-project/rrd-client-lib.svg?branch=master)](https://travis-ci.org/xapi-project/rrd-client-lib)
33

44
# rrd-client-lib - A Library to Provide RRD Data
55

@@ -19,7 +19,6 @@ The `Makefile` builds the library and a simple test. The implementation
1919
relies on a small JSON library that is included as a Git submodule. This
2020
needs to be initialised:
2121

22-
make parson
2322
make
2423

2524
make test
@@ -28,9 +27,7 @@ needs to be initialised:
2827
## Parson
2928

3029
The JSON library [Parson](https://github.com/kgabis/parson.git) is
31-
included as a Git submodule. A submodule points to a specific commit in
32-
an external repository and does not track its master branch as this
33-
advances. Instead, it needs to be updated explicitly.
30+
included as a copy of the source code.
3431

3532
## Documentation - Overview
3633

@@ -45,7 +42,7 @@ library:
4542
int rrd_close(RRD_PLUGIN * plugin);
4643
int rrd_add_src(RRD_PLUGIN * plugin, RRD_SOURCE * source);
4744
int rrd_del_src(RRD_PLUGIN * plugin, RRD_SOURCE * source);
48-
int rrd_sample(RRD_PLUGIN * plugin);
45+
int rrd_sample(RRD_PLUGIN * plugin, time_t (*t)(time_t*));
4946

5047
A plugin reports streams of data to the RRD service. Each such
5148
stream is represented as an `RRD_SOURCE` value. An `RRD_PLUGIN`
@@ -86,7 +83,7 @@ All strings are in UTF8 encoding. The library implements the following
8683
policy to manage memory: it does not free any memory that is hasn't
8784
itself allocated. This means, if the client passes dynamically allocated
8885
data into the library, it is the client's responsibility to de-allocate
89-
it.
86+
it.
9087

9188
## Open, Sample, Close
9289

@@ -105,12 +102,14 @@ considered private to the library.
105102
<<function declarations>>=
106103
RRD_PLUGIN *rrd_open(char *name, rrd_domain_t domain, char *path);
107104
int rrd_close(RRD_PLUGIN * plugin);
108-
int rrd_sample(RRD_PLUGIN * plugin);
105+
int rrd_sample(RRD_PLUGIN * plugin, time_t (*t)(time_t*));
109106

110107

111108
The name of the plugin is descriptive, as whether it reports data
112109
for a single machine (`RRD_LOCAL_DOMAIN`) or multiple
113-
(`RRD_INTER_DOMAIN`).
110+
(`RRD_INTER_DOMAIN`). The second parameter of `rrd_sample` is typically
111+
NULL. If it isn't, it us used to obtain a timestamp instead of using
112+
time(3).
114113

115114
## Data Sources
116115

librrd.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <stdlib.h>
2727
#include <stdio.h>
2828
#include <zlib.h>
29-
#include <time.h>
3029
#include <assert.h>
3130
#include <sys/types.h>
3231
#include <sys/stat.h>
@@ -144,17 +143,27 @@ json_for_source(RRD_SOURCE * source)
144143
}
145144
json_object_set_string(src, "value_type", value_type);
146145

146+
#define RRD_TRANSPORT_1_0_0
147+
#ifdef RRD_TRANSPORT_1_1_0
148+
#define GAUGE "gauge"
149+
#define ABSOLUTE "absolute"
150+
#define DERIVE "derive"
151+
#else
152+
#define GAUGE "absolute"
153+
#define ABSOLUTE "rate"
154+
#define DERIVE "absolute_to_rate"
155+
#endif
147156

148157
char *scale = NULL;
149158
switch (source->scale) {
150159
case RRD_GAUGE:
151-
scale = "gauge";
160+
scale = GAUGE;
152161
break;
153162
case RRD_ABSOLUTE:
154-
scale = "absolute";
163+
scale = ABSOLUTE;
155164
break;
156165
case RRD_DERIVE:
157-
scale = "derive";
166+
scale = DERIVE;
158167
break;
159168
default:
160169
abort();
@@ -390,7 +399,7 @@ write_exact(int fd, const void *data, size_t size)
390399
* first.
391400
*/
392401
int
393-
rrd_sample(RRD_PLUGIN * plugin)
402+
rrd_sample(RRD_PLUGIN * plugin, time_t (*t)(time_t*))
394403
{
395404
assert(plugin);
396405
JSON_Value *json;
@@ -430,7 +439,8 @@ rrd_sample(RRD_PLUGIN * plugin)
430439
/*
431440
* update timestamp, calculate crc
432441
*/
433-
header->rrd_timestamp = htonll((uint64_t) time(NULL));
442+
443+
header->rrd_timestamp = htonll((uint64_t) (t ? t(NULL) : time(NULL)));
434444
uint32_t crc = crc32(0L, Z_NULL, 0);
435445
crc = crc32(crc,
436446
(unsigned char *) &header->rrd_timestamp,

librrd.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
#include <stdint.h>
26+
#include <time.h>
2627
#include "parson/parson.h"
2728

2829
#define RRD_MAX_SOURCES 128
@@ -124,7 +125,10 @@ int rrd_del_src(RRD_PLUGIN * plugin, RRD_SOURCE * source);
124125

125126
/*
126127
* calling rrd_sample(plugin) triggers that all data sources are sampled
127-
* and the results are reported to the RRD daemon. This function needs to
128-
* be called every 5 seconds by the client,
128+
* and the results are reported to the RRD daemon. This function needs
129+
* to be called every 5 seconds by the client. The second parameter is
130+
* typically NULL. If it isn't, it will be used instead of time(3) to
131+
* obtain the time stamp that is written to the RRD file. This can be
132+
* used to create RRD files that don't depend on the current time.
129133
*/
130-
int rrd_sample(RRD_PLUGIN * plugin);
134+
int rrd_sample(RRD_PLUGIN * plugin, time_t (*t)(time_t*));

ocaml/rrdreader.ml

-73
This file was deleted.

parson

-1
This file was deleted.

parson

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
parson-a1c356e

parson-a1c356e/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CC = gcc
2+
CFLAGS = -O0 -g -Wall -Wextra -std=c89 -pedantic-errors
3+
4+
CPPC = g++
5+
CPPFLAGS = -O0 -g -Wall -Wextra
6+
7+
all: test testcpp
8+
9+
.PHONY: test testcpp
10+
test: tests.c parson.c
11+
$(CC) $(CFLAGS) -o $@ tests.c parson.c
12+
./$@
13+
14+
testcpp: tests.c parson.c
15+
$(CPPC) $(CPPFLAGS) -o $@ tests.c parson.c
16+
./$@
17+
18+
clean:
19+
rm -f test *.o
20+

0 commit comments

Comments
 (0)