-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
klogga v0.3
- Loading branch information
Showing
56 changed files
with
1,504 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ The following authors have created the source code of "klogga" <br> | |
published and distributed by AO Kaspersky Lab as the owner: <br> | ||
|
||
Danila Protsenko <[email protected]> <[email protected]> <br> | ||
Artem Doktor <[email protected]> <[email protected]> <br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,91 @@ | ||
# Introduction | ||
Opinionated logging-audit-tracing library. | ||
Data collected via klogga can be configured to be exported to different sources, including traditional text logs, but with emphasis on structured storages, primarily time-series databases and Open Telemetry. | ||
Data collected via **klogga** can be configured to be exported to different sources, including traditional text logs, but with emphasis on structured storages, primarily time-series databases and Open Telemetry. | ||
|
||
The ideology is explained here (in russian) [Logging as fact-stream](https://www.youtube.com/watch?v=1lcKzy6j6-k) | ||
|
||
**klogga** is in development and as of yet does not even have a 1.0 release. | ||
API is subject to changes, although we do not expect any. | ||
It is used extensively in Kaspersky internal projects written in go. | ||
|
||
# Getting Started | ||
import klogga | ||
configure your root tracer, don't forget to use batcher for buffered traces | ||
see examples/tracers_tree.go | ||
## Basic | ||
Import klogga, configure your root tracer, don't forget to use batcher for buffered traces | ||
see [examples](examples/basic_app/main.go) | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/KasperskyLab/klogga" | ||
"github.com/KasperskyLab/klogga/util" | ||
"time" | ||
) | ||
|
||
func main() { | ||
// kreating a factory, with the simplest exporter | ||
tf := util.DefaultFactory() | ||
|
||
// kreating a tracer with a package name | ||
trs := tf.NamedPkg() | ||
|
||
// starting a span | ||
// for now, we'll ignore context | ||
span, _ := klogga.Start(context.Background()) | ||
// span will be written on func exit | ||
defer trs.Finish(span) | ||
|
||
// tag - potentially indexed | ||
span.Tag("app", "hello-world") | ||
// value - for metrics, or bigger values | ||
span.Val("meaning", 42) | ||
// sleep a bit, to have us some non-zero duration | ||
time.Sleep(154 * time.Millisecond) | ||
} | ||
``` | ||
OUTPUT: | ||
``` | ||
2022-02-03 04:05:06.789 I main [main.] main() (155.17ms); app:'hello-world'; meaning:'42'; id: 65C6p2Mq2N4; trace: 4nxwjs5WR9G9A-1-dw4cqA | ||
``` | ||
|
||
## Extended | ||
|
||
**klogga** comes with [fx](https://github.com/uber-go/fx) integration. <br> | ||
See [fx example](examples/fx_app/main.go) | ||
|
||
|
||
# Features and ideas | ||
This list will be covered and structured in the future. | ||
|
||
- logging basic information automatically without manual setup | ||
- logging code information for easy search (uses reflection) | ||
- tracing support: parent-child spans and trace-id | ||
- opentelemetry support | ||
- TODO go fuzz tests | ||
- TODO trace information propagation support for HTTP, GRPC | ||
- TODO transport support | ||
- TODO postgres type mapping customization | ||
- TODO span serialization to protobuf | ||
- TODO elasticsearch exporter (if opentelemetry is not enough) | ||
- TODO more docs for postgreSQL & timescaleDB integration | ||
- TODO increase test coverage (~60% to ~80%) | ||
|
||
|
||
# Running tests | ||
## Unit test | ||
Unit tests do not require any environment, all tests that require environment will be skipped | ||
```shell | ||
go test ./... | ||
``` | ||
|
||
|
||
## Integration tests | ||
Postgresql (timescaleDB) tests can be run on any empty database. | ||
Tests use environment variable KLOGGA_PG_CONNECTION_STRING to connect to PG. | ||
Use [docker-compose.yml](docker-compose.yml) to start default instance. | ||
Default setup: | ||
```shell | ||
podman-compose up -d | ||
KLOGGA_PG_CONNECTION_STRING='user=postgres password=postgres sslmode=disable' go test ./... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/KasperskyLab/klogga" | ||
fxAdapter "github.com/KasperskyLab/klogga/adapters/fx" | ||
"go.uber.org/fx" | ||
"time" | ||
) | ||
|
||
func main() { | ||
fx.New(CreateApp()).Run() | ||
} | ||
|
||
func CreateApp() fx.Option { | ||
return fx.Options( | ||
fx.Provide(NewRunner, | ||
fx.Annotate(func(r *Runner) fxAdapter.Runner { return r }, fxAdapter.TagRunner...)), | ||
fxAdapter.Full(), | ||
fx.Invoke(fxAdapter.RegisterRunners), // register runnerA | ||
) | ||
} | ||
|
||
type Runner struct { | ||
trs klogga.Tracer | ||
stop chan struct{} | ||
} | ||
|
||
func NewRunner(trsFactory klogga.TracerProvider) *Runner { | ||
return &Runner{ | ||
trs: trsFactory.Named("runner_a"), | ||
} | ||
} | ||
|
||
func (r *Runner) Start(ctx context.Context) error { | ||
span := klogga.StartLeaf(ctx) | ||
defer r.trs.Finish(span) | ||
|
||
go func() { | ||
for i := 0; ; i++ { | ||
r.LogSomething(i) | ||
select { | ||
case <-r.stop: | ||
return | ||
case <-time.After(2 * time.Second): | ||
} | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
func (*Runner) Stop(context.Context) error { | ||
return nil | ||
} | ||
|
||
func (r *Runner) LogSomething(iteration int) { | ||
span := klogga.StartLeaf(context.Background(), klogga.WithName("run_func")) | ||
defer r.trs.Finish(span) | ||
span.Val("iteration", iteration) | ||
} |
Oops, something went wrong.