Skip to content

Commit 426e3e7

Browse files
cosmo0920edsiper
authored andcommitted
decode_statsd: Implement statsd decoder
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 29db578 commit 426e3e7

File tree

3 files changed

+674
-0
lines changed

3 files changed

+674
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* CMetrics
4+
* ========
5+
* Copyright 2021-2022 The CMetrics Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
21+
#ifndef CMT_DECODE_STATSD_H
22+
#define CMT_DECODE_STATSD_H
23+
24+
#include <cmetrics/cmetrics.h>
25+
26+
#define CMT_DECODE_STATSD_TYPE_COUNTER 1
27+
#define CMT_DECODE_STATSD_TYPE_GAUGE 2
28+
#define CMT_DECODE_STATSD_TYPE_TIMER 3
29+
#define CMT_DECODE_STATSD_TYPE_SET 4
30+
31+
#define CMT_DECODE_STATSD_SUCCESS 0
32+
#define CMT_DECODE_STATSD_ALLOCATION_ERROR 1
33+
#define CMT_DECODE_STATSD_UNEXPECTED_ERROR 2
34+
#define CMT_DECODE_STATSD_INVALID_ARGUMENT_ERROR 3
35+
#define CMT_DECODE_STATSD_UNEXPECTED_METRIC_TYPE 4
36+
#define CMT_DECODE_STATSD_DECODE_ERROR 5
37+
#define CMT_DECODE_STATSD_UNPACK_ERROR 6
38+
#define CMT_DECODE_STATSD_UNSUPPORTED_METRIC_TYPE 7
39+
#define CMT_DECODE_STATSD_INVALID_TAG_FORMAT_ERROR 8
40+
41+
#define CMT_DECODE_STATSD_GAUGE_OBSERVER 1 << 0
42+
43+
/*
44+
* The "cmt_statsd_message" represents a single line in UDP packet.
45+
* It's just a bunch of pointers to ephemeral buffer.
46+
*/
47+
struct cmt_statsd_message {
48+
char *bucket;
49+
int bucket_len;
50+
char *value;
51+
char *labels;
52+
int value_len;
53+
int type;
54+
double sample_rate;
55+
};
56+
57+
int cmt_decode_statsd_create(struct cmt **out_cmt, char *in_buf, size_t in_size, int flags);
58+
void cmt_decode_statsd_destroy(struct cmt *cmt);
59+
60+
#endif

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(src
3535
cmt_encode_influx.c
3636
cmt_encode_msgpack.c
3737
cmt_decode_msgpack.c
38+
cmt_decode_statsd.c
3839
cmt_mpack_utils.c
3940
external/remote.pb-c.c
4041
external/types.pb-c.c

0 commit comments

Comments
 (0)