Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit d0145c0

Browse files
hydra-zimzhanjiahui
authored andcommitted
remove expire mechanism
1 parent dad4b3b commit d0145c0

8 files changed

Lines changed: 20 additions & 45 deletions

File tree

config.default.json.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"server_name" : "brubeck_debug",
44
"dumpfile" : "./brubeck.dump",
55
"capacity" : 15,
6-
"expire" : 20,
76
"http" : ":8080",
87

98
"backends" : [

src/backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void *backend__thread(void *_ptr)
3030
self->tick_time = now.tv_sec;
3131

3232
for (mt = self->queue; mt; mt = mt->next) {
33-
if (mt->expire > BRUBECK_EXPIRE_DISABLED)
33+
if (mt->state != BRUBECK_STATE_DISABLED)
3434
brubeck_metric_sample(mt, self->sample, self);
3535
}
3636

src/http.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ expire_metric(struct brubeck_server *server, const char *url)
6363
server, url + strlen("/expire/"));
6464

6565
if (metric) {
66-
metric->expire = BRUBECK_EXPIRE_DISABLED;
66+
metric->state = BRUBECK_STATE_DISABLED;
6767
return MHD_create_response_from_data(
6868
0, "", 0, 0);
6969
}
@@ -76,8 +76,8 @@ send_metric(struct brubeck_server *server, const char *url)
7676
static const char *metric_types[] = {
7777
"gauge", "meter", "counter", "histogram", "timer", "internal"
7878
};
79-
static const char *expire_status[] = {
80-
"disabled", "inactive", "active"
79+
static const char *metric_status[] = {
80+
"inactive", "active"
8181
};
8282

8383
struct brubeck_metric *metric = safe_lookup_metric(
@@ -92,7 +92,7 @@ send_metric(struct brubeck_server *server, const char *url)
9292
#else
9393
"shard", 0,
9494
#endif
95-
"expire", expire_status[metric->expire]
95+
"state", metric_status[metric->state]
9696
);
9797

9898
char *jsonr = json_dumps(mj, JSON_INDENT(4) | JSON_PRESERVE_ORDER);

src/internal_sampler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ brubeck_internal__sample(struct brubeck_metric *metric, brubeck_sample_cb sample
5858
* Mark the metric as active so it doesn't get disabled
5959
* by the inactive metrics pruner
6060
*/
61-
metric->expire = BRUBECK_EXPIRE_ACTIVE;
61+
metric->state = BRUBECK_STATE_ACTIVE;
6262
}
6363

6464
void brubeck_internal__init(struct brubeck_server *server)

src/metric.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ new_metric(struct brubeck_server *server, const char *key, size_t key_len, uint8
1515
metric->key[key_len] = '\0';
1616
metric->key_len = (uint16_t)key_len;
1717

18-
metric->expire = BRUBECK_EXPIRE_ACTIVE;
18+
metric->state = BRUBECK_STATE_ACTIVE;
1919
metric->type = type;
2020
pthread_spin_init(&metric->lock, PTHREAD_PROCESS_PRIVATE);
2121

@@ -49,6 +49,7 @@ gauge__record(struct brubeck_metric *metric, value_t value, value_t sample_freq,
4949
} else {
5050
metric->as.gauge.value = value;
5151
}
52+
metric->state= BRUBECK_STATE_ACTIVE;
5253
}
5354
pthread_spin_unlock(&metric->lock);
5455
}
@@ -61,6 +62,7 @@ gauge__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
6162
pthread_spin_lock(&metric->lock);
6263
{
6364
value = metric->as.gauge.value;
65+
metric->state = BRUBECK_STATE_INACTIVE;
6466
}
6567
pthread_spin_unlock(&metric->lock);
6668

@@ -82,6 +84,7 @@ meter__record(struct brubeck_metric *metric, value_t value, value_t sample_freq,
8284
pthread_spin_lock(&metric->lock);
8385
{
8486
metric->as.meter.value += value;
87+
metric->state= BRUBECK_STATE_ACTIVE;
8588
}
8689
pthread_spin_unlock(&metric->lock);
8790
}
@@ -95,6 +98,7 @@ meter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
9598
{
9699
value = metric->as.meter.value;
97100
metric->as.meter.value = 0.0;
101+
metric->state = BRUBECK_STATE_INACTIVE;
98102
}
99103
pthread_spin_unlock(&metric->lock);
100104

@@ -124,6 +128,7 @@ counter__record(struct brubeck_metric *metric, value_t value, value_t sample_fre
124128
}
125129

126130
metric->as.counter.previous = value;
131+
metric->state= BRUBECK_STATE_ACTIVE;
127132
}
128133
pthread_spin_unlock(&metric->lock);
129134
}
@@ -137,6 +142,7 @@ counter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *o
137142
{
138143
value = metric->as.counter.value;
139144
metric->as.counter.value = 0.0;
145+
metric->state = BRUBECK_STATE_INACTIVE;
140146
}
141147
pthread_spin_unlock(&metric->lock);
142148

@@ -155,6 +161,7 @@ histogram__record(struct brubeck_metric *metric, value_t value, value_t sample_f
155161
pthread_spin_lock(&metric->lock);
156162
{
157163
brubeck_histo_push(&metric->as.histogram, value, sample_freq);
164+
metric->state= BRUBECK_STATE_ACTIVE;
158165
}
159166
pthread_spin_unlock(&metric->lock);
160167
}
@@ -168,6 +175,7 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void
168175
pthread_spin_lock(&metric->lock);
169176
{
170177
brubeck_histo_sample(&hsample, &metric->as.histogram);
178+
metric->state = BRUBECK_STATE_INACTIVE;
171179
}
172180
pthread_spin_unlock(&metric->lock);
173181

@@ -187,11 +195,6 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void
187195
sample(key, hsample.count / (double)backend->sample_freq, opaque);
188196
}
189197

190-
/* if there have been no metrics during this sampling period,
191-
* we don't need to report any of the histogram samples */
192-
if (hsample.count == 0.0)
193-
return;
194-
195198
WITH_SUFFIX(".min") {
196199
sample(key, hsample.min, opaque);
197200
}
@@ -333,6 +336,5 @@ brubeck_metric_find(struct brubeck_server *server, const char *key, size_t key_l
333336
brubeck_atomic_inc(&metric->flow);
334337
#endif
335338

336-
metric->expire = BRUBECK_EXPIRE_ACTIVE;
337339
return metric;
338340
}

src/metric.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ enum brubeck_aggregate_t {
2323
};
2424

2525
enum {
26-
BRUBECK_EXPIRE_DISABLED = 0,
27-
BRUBECK_EXPIRE_INACTIVE = 1,
28-
BRUBECK_EXPIRE_ACTIVE = 2
26+
BRUBECK_STATE_INACTIVE = 0,
27+
BRUBECK_STATE_ACTIVE = 1
2928
};
3029

3130
struct brubeck_metric {
@@ -38,7 +37,7 @@ struct brubeck_metric {
3837
pthread_spinlock_t lock;
3938
uint16_t key_len;
4039
uint8_t type;
41-
uint8_t expire;
40+
uint8_t state;
4241

4342
union {
4443
struct {

src/server.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ update_proctitle(struct brubeck_server *server)
6363
setproctitle("brubeck", buf);
6464
}
6565

66-
static void
67-
expire_metric(struct brubeck_metric *mt, void *_)
68-
{
69-
/* If this metric is not disabled, turn "inactive"
70-
* into "disabled" and "active" into "inactive"
71-
*/
72-
if (mt->expire > BRUBECK_EXPIRE_DISABLED)
73-
mt->expire = mt->expire - 1;
74-
}
75-
7666
static void
7767
dump_metric(struct brubeck_metric *mt, void *out_file)
7868
{
@@ -192,7 +182,6 @@ static void load_config(struct brubeck_server *server, const char *path)
192182
json_t *backends, *samplers;
193183

194184
/* optional */
195-
int expire = 0;
196185
char *http = NULL;
197186

198187
server->name = "brubeck";
@@ -211,8 +200,7 @@ static void load_config(struct brubeck_server *server, const char *path)
211200
"capacity", &capacity,
212201
"backends", &backends,
213202
"samplers", &samplers,
214-
"http", &http,
215-
"expire", &expire);
203+
"http", &http);
216204

217205
gh_log_set_instance(server->name);
218206

@@ -224,7 +212,6 @@ static void load_config(struct brubeck_server *server, const char *path)
224212
load_samplers(server, samplers);
225213

226214
if (http) brubeck_http_endpoint_init(server, http);
227-
if (expire) server->fd_expire = load_timerfd(expire);
228215
}
229216

230217
void brubeck_server_init(struct brubeck_server *server, const char *config)
@@ -237,7 +224,6 @@ void brubeck_server_init(struct brubeck_server *server, const char *config)
237224

238225
server->fd_signal = load_signalfd();
239226
server->fd_update = load_timerfd(1);
240-
server->fd_expire = -1;
241227

242228
/* init the memory allocator */
243229
brubeck_slab_init(&server->slab);
@@ -272,7 +258,7 @@ static int signal_triggered(struct pollfd *fd)
272258

273259
int brubeck_server_run(struct brubeck_server *server)
274260
{
275-
struct pollfd fds[3];
261+
struct pollfd fds[2];
276262
int nfd = 2;
277263
size_t i;
278264

@@ -284,11 +270,6 @@ int brubeck_server_run(struct brubeck_server *server)
284270
fds[1].fd = server->fd_update;
285271
fds[1].events = POLLIN;
286272

287-
if (server->fd_expire >= 0) {
288-
fds[2].fd = server->fd_expire;
289-
fds[2].events = POLLIN;
290-
nfd++;
291-
}
292273

293274
server->running = 1;
294275
log_splunk("event=listening");
@@ -315,11 +296,6 @@ int brubeck_server_run(struct brubeck_server *server)
315296
update_flows(server);
316297
update_proctitle(server);
317298
}
318-
319-
if (timer_elapsed(&fds[2])) {
320-
log_splunk("event=expire_metrics");
321-
brubeck_hashtable_foreach(server->metrics, &expire_metric, NULL);
322-
}
323299
}
324300

325301
for (i = 0; i < server->active_backends; ++i)

src/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct brubeck_server {
2727
int active_samplers;
2828

2929
int fd_signal;
30-
int fd_expire;
3130
int fd_update;
3231

3332
struct brubeck_slab slab;

0 commit comments

Comments
 (0)