From: Peter Stamfest Date: Sun, 31 Aug 2014 16:28:51 +0000 (+0200) Subject: Implement mapping X-Git-Tag: v1.5.0-rc1~42^2~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65afd9077434a18f68cd47e4d6595fcde58e11a5;p=thirdparty%2Frrdtool-1.x.git Implement mapping --- diff --git a/src/rrd_create.c b/src/rrd_create.c index ca1c4e46..e2198005 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -1933,17 +1933,29 @@ static void prefill_cdp_prep(candidate_t *target, } static unsigned long find_ds_match(const ds_def_t *ds_def, const rrd_t *src_rrd, - mapping_t *mappings, int mappings_cnt) { + mapping_t *mapping) { unsigned long source_ds_index; + const char *looked_for_ds_name = ds_def->ds_nam; + if (mapping && mapping->mapped_name && strlen(mapping->mapped_name) > 0) { + looked_for_ds_name = mapping->mapped_name; + } for (source_ds_index = 0 ; source_ds_index < src_rrd->stat_head->ds_cnt ; source_ds_index++) { - if (strcmp(ds_def->ds_nam, src_rrd->ds_def[source_ds_index].ds_nam) == 0) { + if (strcmp(looked_for_ds_name, src_rrd->ds_def[source_ds_index].ds_nam) == 0) { return source_ds_index; } } return src_rrd->stat_head->ds_cnt; } +static int find_mapping(const char *ds_nam, const mapping_t *mappings, int mappings_cnt) { + int i; + for (i = 0 ; i < mappings_cnt ; i++) { + if (strcmp(ds_nam, mappings[i].ds_nam) == 0) return i; + } + return -1; +} + /* Find a set of RRAs among all RRA in the sources list, as matched by the select_func and * ordered (by source) according to order_func. */ @@ -1959,11 +1971,18 @@ static candidate_t *find_matching_candidates(const candidate_t *target, const GList *src; candidate_t *candidates = NULL; - - int cnt = 0; - - for (src = sources ; src ; src = g_list_next(src)) { - // first: find matching DS + + int mindex = find_mapping(ds_def->ds_nam, mappings, mappings_cnt); + mapping_t *mapping = mindex < 0 ? NULL : mappings + mindex; + + int cnt = 0, srcindex; + for (src = sources, srcindex = 1 ; src ; src = g_list_next(src), srcindex++) { + // first: check source index if we have a mapping containing an index... + // NOTE: the index is 1-based.... + if (mapping && mapping->index >= 0 && srcindex != mapping->index) { + continue; + } + // then: find matching DS const rrd_file_t *rrd_file = src->data; if (rrd_file == NULL) continue; @@ -1971,7 +1990,7 @@ static candidate_t *find_matching_candidates(const candidate_t *target, const rrd_t *src_rrd = rrd_file->rrd; if (src_rrd == NULL) continue; - unsigned long source_ds_index = find_ds_match(ds_def, src_rrd, mappings, mappings_cnt); + unsigned long source_ds_index = find_ds_match(ds_def, src_rrd, mapping); if (source_ds_index < src_rrd->stat_head->ds_cnt) { // match found diff --git a/tests/Makefile.am b/tests/Makefile.am index 2150d73a..1d8136bd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,7 @@ TESTS = modify1 modify2 modify3 modify4 modify5 \ rrdcreate \ dump-restore \ create-with-source-1 create-with-source-2 create-with-source-3 \ - create-with-source-4 + create-with-source-4 create-with-source-and-mapping-1 EXTRA_DIST = Makefile.am \ alltests functions \ modify1 modify-test1.create.dump modify-test1.mod1.dump \ diff --git a/tests/create-with-source-and-mapping-1 b/tests/create-with-source-and-mapping-1 new file mode 100755 index 00000000..66ed2a5b --- /dev/null +++ b/tests/create-with-source-and-mapping-1 @@ -0,0 +1,100 @@ +#!/bin/bash + +. $(dirname $0)/functions + +BASE=$BASEDIR/$(basename $0)-test +PREFIX=$BUILDDIR/$(basename $0)-test + +# currently, we do not properly copy cdp and pdp information, so for +# comparison of RRD dumps, we just filter out those parts we do not +# expect to match anyway... +function cdp_prep_filter { + perl -n -e '$a=join("",<>); $a=~s,<(cdp_prep).*?,,msg ; print $a' +} + +function pdp_prep_filter { + perl -n -e '$a=join("",<>); $a=~s,<(last_ds|value|unknown_sec).*?,,msg ; print $a' +} + +function data_filter_by_time { + START="$1" + END="$2" +# 7.9666666667e+02 + + perl -n -e 'print unless (m,/ (\d+) -->.*, && $1 >= '$START' && $1 <= '$END')' +} + +FIRST=1300000000 +ST=$FIRST + +RRA="RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2" + +rm -f ${PREFIX}*.rrd ${PREFIX}*.xml +$RRDTOOL create ${PREFIX}ax1.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U $RRA +report createax1 + +$RRDTOOL create ${PREFIX}bx1.rrd --start $(($ST-1)) --step 60 DS:b:GAUGE:120:0:U $RRA +report createbx1 + +$RRDTOOL create ${PREFIX}ay1.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U $RRA +report createay1 + +$RRDTOOL create ${PREFIX}by1.rrd --start $(($ST-1)) --step 60 DS:b:GAUGE:120:0:U $RRA +report createby1 + +$RRDTOOL create ${PREFIX}ac1.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U DS:c:GAUGE:120:0:U $RRA +report createac1 + +$RRDTOOL create ${PREFIX}ac1_a1.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U DS:c:GAUGE:120:0:U $RRA +report createac1_a1 + + +UPDATEAx1= +UPDATEBx1= +UPDATEAy1= +UPDATEBy1= +UPDATEAC1= +V=10 +for A in $(seq $ST 60 $(($ST + 3000)) ) ; do + V2=$(($V * 2)) + V3=$(($V * 3)) + V4=$(($V * 4)) + UPDATEAx1="$UPDATEAx1 $A:$V" + UPDATEBx1="$UPDATEBx1 $A:$V2" + UPDATEAy1="$UPDATEAy1 $A:$V3" + UPDATEBy1="$UPDATEBy1 $A:$V4" + UPDATEAC1="$UPDATEAC1 $A:$V3:$V" + V=$(($V + 20)) + ST=$A +done + + +$RRDTOOL update ${PREFIX}ax1.rrd $UPDATEAx1 +$RRDTOOL update ${PREFIX}bx1.rrd $UPDATEBx1 +$RRDTOOL update ${PREFIX}ay1.rrd $UPDATEAy1 +$RRDTOOL update ${PREFIX}by1.rrd $UPDATEBy1 +$RRDTOOL update ${PREFIX}ac1.rrd $UPDATEAC1 +$RRDTOOL update ${PREFIX}ac1_a1.rrd --template a $UPDATEAx1 + +SOURCES="--source ${PREFIX}ax1.rrd --source ${PREFIX}bx1.rrd --source ${PREFIX}ay1.rrd --source ${PREFIX}by1.rrd" + +$RRDTOOL create ${PREFIX}ac2_a1.rrd --start $ST --step 60 $SOURCES DS:a:GAUGE:120:0:U DS:c:GAUGE:120:0:U $RRA +report create-ac2_a1-from-sources-unmapped + +$RRDTOOL dump ${PREFIX}ac1_a1.rrd > ${PREFIX}ac1_a1.xml +$RRDTOOL dump ${PREFIX}ac2_a1.rrd > ${PREFIX}ac2_a1.xml +$DIFF ${PREFIX}ac1_a1.xml ${PREFIX}ac2_a1.xml +report match-ac1_a1 + + +$RRDTOOL create ${PREFIX}ac2.rrd --start $ST --step 60 $SOURCES DS:a=a[3]:GAUGE:120:0:U DS:c=a[1]:GAUGE:120:0:U $RRA +report create-ac2-from-same-ds-names-sources + +$RRDTOOL dump ${PREFIX}ac1.rrd > ${PREFIX}ac1.xml +$RRDTOOL dump ${PREFIX}ac2.rrd > ${PREFIX}ac2.xml +$DIFF ${PREFIX}ac1.xml ${PREFIX}ac2.xml +report match-ac1 + + + +rm -f ${PREFIX}*.rrd ${PREFIX}*.xml