prjcfg

package
v0.0.0-...-110cdec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package prjcfg handles project-scoped CV config.

TODO(crbug/1221908): implement pruning of old configs.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the current DS schema version.

Bump it to force-update Project configs and their Config Groups after the next deployment.

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(cfg *cfgpb.Config) (string, error)

ComputeHash computes the hash string of given CV Config and prefixed with hash algorithm string. (e.g. sha256:deadbeefdeadbeef)

The hash string is an hex-encoded string of the first 8 bytes (i.e. 16 char in length) of sha256(deterministically binary serialized Config proto). Note that, deterministic marshalling does NOT guarantee the same output for the equal proto message across different language or event builds. Therefore, in worst case scenario, when a newer version of proto lib is deployed, CV may re-ingest functionally equivalent config. See: https://godoc.org/google.golang.org/protobuf/proto#MarshalOptions

func GerritHost

func GerritHost(cfg *cfgpb.ConfigGroup_Gerrit) string

GerritHost returns Gerrit host.

Panics if config is not valid.

func GetAllGerritHosts

func GetAllGerritHosts(ctx context.Context) (map[string]stringset.Set, error)

GetAllGerritHosts returns a map of the Gerrit hosts watched by enabled LUCI projects.

func GetAllProjectIDs

func GetAllProjectIDs(ctx context.Context, enabledOnly bool) ([]string, error)

GetAllProjectIDs returns the names of all projects available in datastore.

func MustComputeHash

func MustComputeHash(cfg *cfgpb.Config) string

MustComputeHash is like ComputeHash but panics on error.

func ProjectConfigKey

func ProjectConfigKey(ctx context.Context, project string) *datastore.Key

ProjectConfigKey returns the ProjectConfig key for a given project.

Types

type ConfigGroup

type ConfigGroup struct {
	Project *datastore.Key `gae:"$parent"`
	ID      ConfigGroupID  `gae:"$id"`
	// SchemaVersion is the version of the schema.
	//
	// It is used to force-update old entities to newest format.
	// See SchemaVersion const.
	SchemaVersion int `gae:",noindex"`
	// DrainingStartTime represents `draining_start_time` in the CV config.
	//
	// Note that this is a project-level field. Therefore, all ConfigGroups in a
	// single version of config should have the same value.
	DrainingStartTime string `gae:",noindex"`
	// SubmitOptions represents `submit_options` field in the CV config.
	//
	// Note that this is currently a project-level field. Therefore, all
	// ConfigGroups in a single version of Config should have the same value.
	SubmitOptions *cfgpb.SubmitOptions
	// HonorGerritLinkedAccounts tells whether LUCI CV should also honor linked
	// accounts in Gerrit.
	//
	// That means all linked secondary accounts and primary accounts will share
	// the same permission from LUCI CV points of view.
	//
	// Note that this is currently a project-level field. Therefore, all
	// ConfigGroups in a single version of Config should have the same value.
	HonorGerritLinkedAccounts bool `gae:",noindex"`
	// Content represents a `pb.ConfigGroup` proto message defined in the CV
	// config
	Content *cfgpb.ConfigGroup
	// CQStatusHost is the URL of the CQ status app. Optional.
	//
	// Deprecated.
	// TODO(crbug/1233963): remove this field.
	CQStatusHost string `gae:",noindex"`
	// contains filtered or unexported fields
}

ConfigGroup is an entity that represents a ConfigGroup defined in CV config.

func GetConfigGroup

func GetConfigGroup(ctx context.Context, project string, id ConfigGroupID) (*ConfigGroup, error)

GetConfigGroup loads ConfigGroup from datastore if exists.

To handle non-existing ConfigGroup, use datastore.IsErrNoSuchEntity. Doesn't check whether validity or existence of the given LUCI project.

func (*ConfigGroup) ProjectString

func (c *ConfigGroup) ProjectString() string

ProjectString returns LUCI Project as a string.

type ConfigGroupID

type ConfigGroupID string

ConfigGroupID is the ID for ConfigGroup Entity.

It is in the format of "hash/name" where

  • `hash` is the `Hash` field in the containing `ProjectConfig`.
  • `name` is the value of `ConfigGroup.Name`.

func MakeConfigGroupID

func MakeConfigGroupID(hash, name string) ConfigGroupID

MakeConfigGroupID creates ConfigGroupID.

func (ConfigGroupID) Hash

func (c ConfigGroupID) Hash() string

Hash returns Hash of the corresponding project config.

func (ConfigGroupID) Name

func (c ConfigGroupID) Name() string

Name returns name component only.

type ConfigHashInfo

type ConfigHashInfo struct {

	// Hash is the `Hash` of a `ProjectConfig` that CV has imported.
	Hash    string         `gae:"$id"`
	Project *datastore.Key `gae:"$parent"`
	// SchemaVersion is the version of the schema.
	//
	// It is used to force-update old entities to newest format.
	// See SchemaVersion const.
	SchemaVersion int `gae:",noindex"`
	// GitRevision is the git revision (commit hash) of the imported config.
	GitRevision string `gae:",noindex"`
	// ProjectEVersion is largest version of ProjectConfig that this `Hash`
	// maps to.
	//
	// It is possible for a ConfigHash maps to multiple EVersions (e.g. a CV
	// Config change is landed then reverted which results in two new EVersions
	// but only one new Hash). Only the largest EVersion matters when cleanup
	// job runs (i.e. CV will keep the last 5 EVersions).
	ProjectEVersion int64 `gae:",noindex"`
	// UpdateTime is the timestamp when this ConfigHashInfo was last updated.
	UpdateTime time.Time `gae:",noindex"`
	// ConfigGroupNames are the names of all ConfigGroups with this `Hash`.
	ConfigGroupNames []string `gae:",noindex"`
	// contains filtered or unexported fields
}

ConfigHashInfo stores high-level info about a ProjectConfig `Hash`.

It is primarily used for cleanup purpose to decide which `Hash` and its corresponding `ConfigGroup`s can be safely deleted.

type Meta

type Meta struct {
	// Project is LUCI Project ID.
	Project string
	// Status is status of the LUCI project config.
	Status Status
	// EVersion allows to compare progression of Project's config.
	//
	// Larger values means later config.
	// If StatusNotExists, the value is 0.
	EVersion int64
	// ConfigGroupNames are the names part of all ConfigGroups in this version.
	//
	// If project doesn't exist, empty.
	// Otherwise, contains at least one group.
	ConfigGroupNames []string
	// ConfigGroupIDs are the standalone IDs of all ConfigGroups in this version.
	//
	// If project doesn't exist, empty.
	// Otherwise, contains at least one group.
	ConfigGroupIDs []ConfigGroupID
	// contains filtered or unexported fields
}

Meta describes LUCI project's config version.

func GetHashMeta

func GetHashMeta(ctx context.Context, project, hash string) (Meta, error)

GetHashMeta returns metadata for a project for a given config hash.

Doesn't check whether a project currently exists. Returns error if specific (project, hash) combo doesn't exist in Datastore.

func GetHashMetas

func GetHashMetas(ctx context.Context, project string, hashes ...string) ([]Meta, error)

GetHashMetas returns a metadata for each given config hash.

Doesn't check whether a project currently exists. Returns error if any (project, hash) combo doesn't exist in Datastore.

func GetLatestMeta

func GetLatestMeta(ctx context.Context, project string) (Meta, error)

GetLatestMeta returns latest metadata for a project.

func (*Meta) Exists

func (m *Meta) Exists() bool

Exists returns whether project config exists.

func (Meta) GetConfigGroups

func (m Meta) GetConfigGroups(ctx context.Context) ([]*ConfigGroup, error)

GetConfigGroups loads all ConfigGroups from datastore for this meta.

Meta must correspond to an existing project.

func (*Meta) Hash

func (m *Meta) Hash() string

Hash returns unique identifier of contents of the imported Project config.

Panics if project config doesn't exist.

type ProjectConfig

type ProjectConfig struct {

	// Project is the name of this LUCI Project.
	Project string `gae:"$id"`
	// SchemaVersion is the version of the schema.
	//
	// It is used to force-update old entities to newest format.
	// See SchemaVersion const.
	SchemaVersion int `gae:",noindex"`
	// Enabled indicates whether CV is enabled for this LUCI Project.
	//
	// Project is disabled if it is de-registered in LUCI Config or it no longer
	// has CV config file.
	Enabled bool
	// UpdateTime is the timestamp when this ProjectConfig was last updated.
	UpdateTime time.Time `gae:",noindex"`
	// EVersion is the latest version number of this ProjectConfig.
	//
	// It increments by 1 every time a new config change is imported to CV for
	// this LUCI Project.
	EVersion int64 `gae:",noindex"`
	// Hash is a string computed from the content of latest imported CV Config
	// using `ComputeHash()`.
	Hash string `gae:",noindex"`
	// ExternalHash is the hash string of this CV config in the external source
	// of truth (currently, LUCI Config). Used to quickly decided whether the
	// Config has been updated without fetching the full content.
	ExternalHash string `gae:",noindex"`
	// ConfigGroupNames are the names of all ConfigGroups in the current version
	// of CV Config.
	ConfigGroupNames []string `gae:",noindex"`
	// contains filtered or unexported fields
}

ProjectConfig is the root entity that keeps track of the latest version info of the CV config for a LUCI Project. It only contains high-level metadata about the config. The actual content of config is stored in the `ConfigGroup` entities which can be looked up by constructing IDs using `ConfigGroupNames` field.

type Status

type Status int

Status of LUCI Project Config from CV perspective.

const (
	// StatusNotExists means CV doesn't have config for a LUCI prject.
	//
	// The LUCI project itself may exist in LUCI-Config service.
	StatusNotExists Status = iota
	// StatusDisabled means CV has LUCI project's config, but either CV was
	// disabled for the project or the project was deactivated LUCI-wide.
	StatusDisabled
	// StatusEnabled means CV has LUCI project's config and CV is active for the
	// project.
	StatusEnabled
)

Directories

Path Synopsis
Package prjcfgtest eases controlling of project configs in test.
Package prjcfgtest eases controlling of project configs in test.
Package refresher handles RefreshProjectConfigTask.
Package refresher handles RefreshProjectConfigTask.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL