misura
misura wraps an interface or a struct and adds prometheus metrics such as success count, error count, total count and duration
THIS IS A WIP
TODO
- Handle slice ... operator
- Only work on targets passed not all interfaces in file
- Pass method name and other method related information Total, Success and Error
- Get list of targets not just one
-
Check generated file exists, if yes append to it.
- Create a seperate file for each target.
- Let users decided what metrics they want
- Handle
time package conflict
- Add struct wrapping support?
- Only methods in the same file will be included
- Add an options to create an interface for the struct aswell
- Enable users to extend wrapping functionallity to add custom logic to their interfaces
-
Custom metrics? This is solved by accepting metrics interface.
- Per type method inclusion and exlusion
- Support both go:generate misura [args] and //misura: [args]
- Support third party types
Usage
Assume we have the following interface in a .go file.
type IPUtil interface {
PublicIP() (net.IP, error)
LocalIPs() ([]net.IP, error)
}
Now to generate a wrapper for this interface we have 2 options:
- Put a magic comment for the entire file and passing each interface name with the -t flag.
TODO: add multiple targets using multiple -t args
//go:generate misura -m all -t IPUtil
type IPUtil interface {
PublicIP() (net.IP, error)
LocalIPs() ([]net.IP, error)
}
- Add a magic comment on top of the file then use
//misura:<taget-name> [args] syntax. This method makes the file readable.
package main
//go:generate misura
import (
...
)
//misura:IPUtil -m all
type IPUtil interface {
PublicIP() (net.IP, error)
LocalIPs() ([]net.IP, error)
}
Testing
go test ./...
- Test generated wrappers for compliation
- Test generated code is as expected using
ast, or maybe run them with a utilty program and run it that way.
TODO