Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

klient: rework logging - #8947

Merged
cihangir merged 20 commits into
masterfrom
gateway-client
Sep 16, 2016
Merged

cihangir merged 20 commits into
masterfrom
gateway-client

Conversation

@rjeczalik

@rjeczalik rjeczalik commented Sep 5, 2016 •

Copy link
Copy Markdown
Contributor

deps: #8904

This PR reworks logging in klient, making it possible to upload arbitrary log files from remote machines using keygen and logrotate packages. Please take a look.

This PR also adds "log.upload" method to klient kite, which allows for adding e.g. kd upload command if needed. /cc @leeola

@rjeczalik rjeczalik added the wip label Sep 5, 2016
@rjeczalik
rjeczalik force-pushed the gateway-client branch 5 times, most recently from fc8476d to 0b0acb3 Compare September 8, 2016 22:10
Comment thread config/generateKonfig.coffee Outdated
userPublicKey: credentials.kloud.userPublicKey
userPrivateKey: credentials.kloud.userPrivateKey

keygenAccessKey: credentials.kloud.gatewayAccessKey

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could change the var name in configs too for the sake of consistency

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var req *UploadRequest

switch n, v, _ := reflect.Select(cases); n {
case 0:

@cihangir cihangir Sep 9, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to select our cases with a reflected channel selection?

@rjeczalik rjeczalik Sep 9, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do be able to select on dynamic number of channels.

Alternative would be something like:

tickers := []*time.Ticker{}

...

loop:
    for {
        for _, i := range rand.Perm(len(tickers)) {
            switch {
            case <-tickers[i].C:
                // ...
                // handling here
                // ...
                continue loop
            default:
                continue
            }
        }
    }

I find the reflect more readable & simpler (and more performant, the above will busy wait instead of yielding to gosched, as reflect.Select does).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think another way to do that could be

    for {
        select {
        case <-up.close:
            return
        case req := <-up.req:
            go func() {
                t := time.NewTicker(req.Interval)
                for {
                    select {
                    case <-up.close:
                        t.Stop()
                        return
                    case <-t.C:
                        // do your magic here
                    }
                }
            }()
            // do your magic here, for the first time
        }
    }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please check if the files are already listened/watched by another ticker, multiple requests to kite.upload logs could result in multiple tickers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would work, but I don't like starting additional goroutines for something, that could be done in one. In my opinion it's easier to reason about concurrency and do not worry about leaking goroutines.

Your call, if you find it easier to read I can rework reflect.Select to multiple goroutines. :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please check if the files are already listened/watched by another ticker

done in ee06999

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have different takes on readability :)

Since you said "your call" lets change it to non-reflected version not to fiddle with the runtime memory 🙋

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d59fe50

@leeola

leeola commented Sep 9, 2016

Copy link
Copy Markdown
Contributor

LGTM

@rjeczalik

rjeczalik commented Sep 9, 2016 •

Copy link
Copy Markdown
Contributor Author

@leeola @cihangir Added one more - d378695. Please take a look.

@rjeczalik
rjeczalik force-pushed the gateway-client branch 3 times, most recently from d933368 to 09bdb7f Compare September 9, 2016 22:52
@leeola

leeola commented Sep 10, 2016

Copy link
Copy Markdown
Contributor

👍, LGTM

Since the final key is generated by logrotate depending
on the part sequence number, we need to pass the effective
url down from logrotate.

This PR reworks whole call chain to get the url in uploader
package.
In debug mode the are a lot of lines like:

  2016-09-10T07:39:07.65Z  DEBUG    [tunnelclient ][PID:69307][logging/context.go:53] [transport] Opening a new stream from server session

Which are >128 characters. This makes logrotate errornously
no rotating log files. Increasing the checksum size 256
fixes the problem.
@cihangir
cihangir merged commit bd1dea3 into master Sep 16, 2016
@cihangir
cihangir deleted the gateway-client branch September 16, 2016 12:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants