Skip to content

context, registry, auth, auth/token, cmd/registry: context aware logging - #151

Merged
stevvooe merged 6 commits into
distribution:masterfrom
stevvooe:context-aware-logging
Feb 10, 2015
Merged

stevvooe merged 6 commits into
distribution:masterfrom
stevvooe:context-aware-logging

Conversation

@stevvooe

@stevvooe stevvooe commented Feb 6, 2015

Copy link
Copy Markdown
Collaborator

The new context package supports context-aware logging, integrating with logrus. Several utilities are provided to associate http requests with a context, ensuring that one can trace log messages all the way through a context-aware call stack.

With the creation of that package, we've integrated contextual logging into the registry web application. Idiomatic context use is attempted within the current webapp layout. The functionality is centered around making lifecycle objects (application and request context) into contexts themselves. Relevant data has been moved into the context where appropriate. We still have some work to do to factor out the registry.Context object and the dispatching functionality to remove some awkward portions.

The api tests were slightly refactored to use a test environment to eliminate common code.

logrus and uuid have been updated, accordingly.

Closes #86.

@stevvooe stevvooe added this to the Registry/Beta milestone Feb 6, 2015
@dmcgowan

dmcgowan commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator

It looks good, there might be some optimizations possible to reduce the number of values checks to get a logger instance. Also I like having it in the registry objects, but we should come up with another way when dealing with the exposed storage interfaces.

@dmcgowan

dmcgowan commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator

Where is "http.request.startedat" supposed to get set?

There don't seem to be any major changes but we'll update this while we're at
it. This dependency is pretty important for coming changes.

Signed-off-by: Stephen J Day <[email protected]>
This dependency added a method to access the current standard logger. This is
required to properly configure the logger for context awareness. The plan is to
have all loggers descend from the standard logger.

Signed-off-by: Stephen J Day <[email protected]>
The new context package supports context-aware logging, integrating with
logrus. Several utilities are provided to associate http requests with a
context, ensuring that one can trace log messages all the way through a
context-aware call stack.

A full description of this functionality is available in doc.go.

Signed-off-by: Stephen J Day <[email protected]>
@dmcgowan

dmcgowan commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator

Would it also make sense to integrate the dapper like functionality here? Since it is defining a request context, additional variables could be added to logs for trace/parent/span id, and included in the http headers.
Zipkin has good documentation for setting this up http://twitter.github.io/zipkin/, I think it would be a great PoC of the value of doing this level of contextual logging.

@stevvooe
stevvooe force-pushed the context-aware-logging branch from 125fe9a to 9530175 Compare February 7, 2015 00:23
@stevvooe

stevvooe commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator Author

Where is "http.request.startedat" supposed to get set?

That gets set in WithRequest.

@stevvooe

stevvooe commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator Author

Would it also make sense to integrate the dapper like functionality here? Since it is defining a request context, additional variables could be added to logs for trace/parent/span id, and included in the http headers.
Zipkin has good documentation for setting this up http://twitter.github.io/zipkin/, I think it would be a great PoC of the value of doing this level of contextual logging.

This is partially the goal. Log fields, like "version", "app.id" and "http.request.id", all contribute to this. However, we don't have a standardized, distributed "request.id" or "session" id to be shared through requests. This is something that we should work towards.

@stevvooe

stevvooe commented Feb 7, 2015

Copy link
Copy Markdown
Collaborator Author

@dmcgowan

Also I like having it in the registry objects, but we should come up with another way when dealing with the exposed storage interfaces.

I'm looking at this now. The simplest modification is this:

// Registry represents a collection of repositories, addressable by name.
type Registry interface {
    // Repository should return a reference to the named repository. The
    // registry may or may not have the repository but should always return a
    // reference.
    Repository(ctx context.Context, name string) Repository
}

Basically, we need to be careful about where we can inject the context. The more functions we include it in the signature, the more granularity we get with context reporting. For most use cases, something like this might actually work:

// Repository is a named collection of manifests and layers.
type Repository interface {
    // Name returns the name of the repository.
    Name() string

    // Manifests returns a reference to this repository's manifest service.
    Manifests(ctx context.Context) ManifestService

    // Layers returns a reference to this repository's layers service.
    Layers(ctx context.Context) LayerService
}

There are a few questions with this. How granular do we need the context? Do we use the context as an injection platform?

@stevvooe
stevvooe force-pushed the context-aware-logging branch from 9530175 to 41a332c Compare February 7, 2015 00:45
This changeset integrates contextual logging into the registry web application.
Idiomatic context use is attempted within the current webapp layout. The
functionality is centered around making lifecycle objects (application and
request context) into contexts themselves. Relevant data has been moved into
the context where appropriate.  We still have some work to do to factor out the
registry.Context object and the dispatching functionality to remove some
awkward portions.

The api tests were slightly refactored to use a test environment to eliminate
common code.

Signed-off-by: Stephen J Day <[email protected]>
This changeset integrates context with the storage package. Debug messages have
been added to exported methods. Existing log messages will now include
contextual details through logger fields to aid in debugging. This integration
focuses on logging and may be followed up with a metric-oriented change in the
future.

Signed-off-by: Stephen J Day <[email protected]>
@stevvooe stevvooe changed the title [WIP] context, registry, auth, auth/token, cmd/registry: context aware logging context, registry, auth, auth/token, cmd/registry: context aware logging Feb 9, 2015
@jlhawn

jlhawn commented Feb 10, 2015

Copy link
Copy Markdown

auth-related changes LGTM

@dmp42

dmp42 commented Feb 10, 2015

Copy link
Copy Markdown
Contributor

LGTM

stevvooe added a commit that referenced this pull request Feb 10, 2015
context, registry, auth, auth/token, cmd/registry: context aware logging
@stevvooe
stevvooe merged commit 4be40d1 into distribution:master Feb 10, 2015
@stevvooe
stevvooe deleted the context-aware-logging branch February 10, 2015 23:02
@stevvooe stevvooe removed this from the Registry/2.0.0-beta milestone Mar 31, 2015
@stevvooe stevvooe modified the milestones: Registry/2.0, Registry/2.0.0-beta Mar 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add contextual logging to registry app and storage

4 participants