Message from discussion
[ANN] go-librato and go-metrics
Received: by 10.224.184.5 with SMTP id ci5mr10459384qab.5.1322051919032;
Wed, 23 Nov 2011 04:38:39 -0800 (PST)
X-BeenThere: golang-nuts@googlegroups.com
Received: by 10.229.117.197 with SMTP id s5ls4042074qcq.3.gmail; Wed, 23 Nov
2011 04:38:29 -0800 (PST)
Received: by 10.224.87.81 with SMTP id v17mr10485057qal.8.1322051909650;
Wed, 23 Nov 2011 04:38:29 -0800 (PST)
Received: by 10.224.87.81 with SMTP id v17mr10485055qal.8.1322051909638;
Wed, 23 Nov 2011 04:38:29 -0800 (PST)
Return-Path: <rogpe...@gmail.com>
Received: from mail-qw0-f41.google.com (mail-qw0-f41.google.com [209.85.216.41])
by gmr-mx.google.com with ESMTPS id y8si7808092qcq.0.2011.11.23.04.38.29
(version=TLSv1/SSLv3 cipher=OTHER);
Wed, 23 Nov 2011 04:38:29 -0800 (PST)
Received-SPF: pass (google.com: domain of rogpe...@gmail.com designates 209.85.216.41 as permitted sender) client-ip=209.85.216.41;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of rogpe...@gmail.com designates 209.85.216.41 as permitted sender) smtp.mail=rogpe...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by mail-qw0-f41.google.com with SMTP id 15so312156qap.14
for <golang-nuts@googlegroups.com>; Wed, 23 Nov 2011 04:38:29 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:cc:content-type:content-transfer-encoding;
bh=UmZaSzbDGlpjKctR8VBedltGJpHU53rGtmzVvwtQqZ0=;
b=hCUb5P4ePkj1k9MlCXYEfGNg/7t6PVYTRzU/mZk4P1uSvRDsR0t0ppsucSVs98L0m2
fn2TY1xg3lsyJGHVlWxFOoEO4B4JgxYrqkq7b7YoDxi1ijTiuW8tZfN5H5ygM/xJNvnP
98v3Wl1L8YVasafue1C3AqOWQrQrcMZzWyN0M=
MIME-Version: 1.0
Received: by 10.224.199.134 with SMTP id es6mr10645194qab.2.1322051909480;
Wed, 23 Nov 2011 04:38:29 -0800 (PST)
Received: by 10.229.43.91 with HTTP; Wed, 23 Nov 2011 04:38:29 -0800 (PST)
In-Reply-To: <CANLtmk35EvkcuWDqpYrMOahpN+d5cCvhspsLFLJ2Ja5k7Zg0WA@mail.gmail.com>
References: <CANLtmk19+mquvm5egCp6aH6McnjhPJ3ZqJ+keixg=eaM--v...@mail.gmail.com>
<CAJhgaciC+BtpsM2-cEoweHuqwSidmCmQaQ4fF=4AEvMSCTf...@mail.gmail.com>
<CANLtmk35EvkcuWDqpYrMOahpN+d5cCvhspsLFLJ2Ja5k7Zg...@mail.gmail.com>
Date: Wed, 23 Nov 2011 12:38:29 +0000
Message-ID: <CAJhgaciCk5rt=YjKR7e5+ek=vLUZ5-Pi=76w7WFKhZ+NBPx...@mail.gmail.com>
Subject: Re: [go-nuts] [ANN] go-librato and go-metrics
From: roger peppe <rogpe...@gmail.com>
To: Richard Crowley <r...@rcrowley.org>
Cc: golang-nuts <golang-nuts@googlegroups.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On 23 November 2011 05:46, Richard Crowley <r...@rcrowley.org> wrote:
> Thanks for all your comments, Roger! =C2=A0See answers inline:
>
>> Hi Richard,
>>
>> I've just had a very brief glance at your metrics package - I just
>> did goinstall github.com/codahale/metrics then godoc.
>> So these comments are a very shallow first reaction to
>> the API - please take with a pinch of salt.
>>
>> - There are no doc comments on any of the functions.
>> All exported functions and types should have some documentation.
>
> Caught me. =C2=A0I've added most of them.
cool.
point of information: function and type comments in Go
are conventionally written as complete sentences.
for instance "CaptureRuntimeMemStats captures new values for..."
rather than "Captures new values for...".
>> - it seems that Log and Syslog do very similar things and could
>> probably be merged (the disparity between log and log/syslog
>> doesn't make this very easy though, I agree).
>
> They are very similar in structure, yes, but the log format and API
> are different. =C2=A0This isn't a dig on Go but sometimes it's just easie=
r
> to almost duplicate code.
i agree that it's easier sometimes, but in this case it's fairly
trivial to make them both use the same code.
for example: http://paste.ubuntu.com/746937/
>> - in quite a few places you return interfaces, and it's not
>> obvious that it wouldn't be just fine to use static types instead
>> (for example Registry, Healthcheck, Timer)
>
> All of these were conscious decisions. =C2=A0Many objects in many program=
s
> have (some metric)-like behavior which I want to allow registering as
> metrics.
i see that there are some useful interfaces there - i'm not saying
that you don't want to define interfaces for the things passed
into Registry for example. but i think that things would
be more obvious if the New functions returned statically defined
types - for instance if NewRegistry returned *StandardRegistry
rather than the interface.
i wonder what kind of advantage you're seeing to having
Registry, in particular, as an interface. as it is, it's just
a repository for information. what other kinds of Registries
do you see being useful?
in fact, thinking about this a bit more, i am not sure that
i see how it is advantageous to have the Registry hold
all those specific types.
it seems to me that the only thing all those kinds of things
that can be registered need to have in common is the
ability to print their information to a log.
why not just something like this:
type Logger interface {
Log(printf func(string, ...interface{}))
}
type Registry struct {
mu sync.Mutex
stats map[string] Logger
}
func (r *Registry) Register(name string, stat Logger)
func (r *Registry) Unregister(name string)
func (r *Registry) Get(name string) Logger
func (r *Registry) Each(func(Logger))
then each useful stats-related New function could just
return its static type (e.g. func NewHistogram()*StandardHistogram),
and if there are some useful interfaces in common they can be abstracted ou=
t
independently.
for example:
// writeHistograms writes SVG output to w for all the
// histograms registered with the Registry.
func writeHistograms(r *Registry, w io.Writer) {
r.Each(func(l Logger) {
if h, ok :=3D l.(Histogram); ok {
p :=3D h.Percentile(...)
// etc
}
}
}
by going this way you remove, i think, quite a lot of boilerplate
code without making things any harder to use or less general.
and interfaces are used in the way they work best - to express
commonalities of functionality.