luci: Index | Files

package config

import ""

Package config implements common LogDog daemon configuration.

The majority of LogDog configuration is loaded from "luci-config". The specific "luci-config" instance is passed to the daemon by the LogDog Coordaintor service. This library implements the logic to pull the configuration paramerers, load the "luci-config" configuration, and expose it to the service daemon.

Additionally, for testing, an option is implemented that allows the user to read the configuration from a local file (as a text protobuf) instead of from the Coordinator.


Package Files

cache.go doc.go opts.go poller.go

type CacheOptions Uses

type CacheOptions struct {
    // CacheExpiration is the amount of time that a config entry should be cached.
    // If this value is <= 0, no configuration caching will be enabled. This
    // should not be set for production systems.
    CacheExpiration time.Duration

    // DatastoreCacheAvailable, if true, indicates that requisite services for
    // datastore cache access are installed in the Context. This requires:
    // - A luci/gae datastore service instnace
    // - A settings service instance, presumably gaesettings.
    DatastoreCacheAvailable bool

CacheOptions is the set of configuration options.

func (*CacheOptions) WrapBackend Uses

func (o *CacheOptions) WrapBackend(c context.Context, base backend.B) context.Context

WrapBackend wraps the supplied base backend in caching layers and returns a Context with the resulting backend installed.

type ChangePoller Uses

type ChangePoller struct {
    // ConfigSet is the slice of config paths to watch.
    ConfigSet config.Set
    // Path is the path of the config to watch.
    Path string

    // Period is the amount of time in between checks to see if the configuration
    // has been updated. If <= 0, the poller will refrain from polling, and Run
    // will immediately exit.
    Period time.Duration
    // OnChange is the function that will be called if a configuration change has
    // been observed.
    // Polling will be blocked until OnChange returns. If the Context supplied to
    // Run is canceled by OnChange, Run will exit at the beginning of the next
    // poll round.
    OnChange func()

    // ContentHash is the config's hash. This should be set to the initial config
    // value, either directly or via a Refresh call, before Run is called.
    ContentHash string

ChangePoller polls a configuration files for changes. If it changes, the OnChange function will be called and the polling will stop.

func (*ChangePoller) Refresh Uses

func (p *ChangePoller) Refresh(c context.Context) error

Refresh reloads the configuration value, updating ContentHash.

func (*ChangePoller) Run Uses

func (p *ChangePoller) Run(c context.Context)

Run starts polling for changes. It will stop when the Context is cancelled.

type MessageCache Uses

type MessageCache struct {
    // Lifetime is the lifetime applied to an individual cache entry. If Lifetime
    // is <= 0, no caching will occur.
    Lifetime time.Duration

MessageCache is an in-memory configuration cache. Unlike the "MessageCache" config Backend, this stores the unmarshaled configuration object in-memory.

func (*MessageCache) Get Uses

func (mc *MessageCache) Get(c context.Context, cset config.Set, path string, msg proto.Message) (
    proto.Message, error)

Get returns an unmarshalled configuration service text protobuf message.

If the message is not currently in the process cache, it will be fetched from the config service and cached prior to being returned.

func (*MessageCache) GetUncached Uses

func (mc *MessageCache) GetUncached(c context.Context, cset config.Set, path string,
    msg proto.Message) error

GetUncached returns an unmarshalled configuration service text protobuf message. This bypasses the cache, and, on success, does not cache the resulting value.

Package config imports 16 packages (graph) and is imported by 2 packages. Updated 2020-05-31. Refresh now. Tools for package owners.