common

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package common implements common functionality for the Tricium service modules.

Index

Constants

View Source
const (
	AnalysisResultsQueue = "bigquery-analysis-results-queue"
	AnalyzeQueue         = "analyze-queue"
	DriverQueue          = "driver-queue"
	FeedbackEventsQueue  = "bigquery-feedback-events-queue"
	GerritReporterQueue  = "gerrit-reporter-queue"
	LauncherQueue        = "launcher-queue"
	PollProjectQueue     = "poll-project-queue"
	TrackerQueue         = "tracker-queue"
)

Task queue names.

Variables

View Source
var BuildbucketServer buildbucketServer

BuildbucketServer implements the ServerAPI for the buildbucket service.

View Source
var EventsLog = bqlog.Log{
	QueueName: FeedbackEventsQueue,
	DatasetID: "events",
	TableID:   "feedback",
}

EventsLog includes rows for events, such as "not useful" clicks and sending of comments.

View Source
var MockPubSub mockPubSub

MockPubSub mocks the PubSub interface for testing.

View Source
var MockTaskServerAPI mockTaskServerAPI

MockTaskServerAPI mocks the TaskServerAPI interface for testing.

View Source
var PubsubServer pubsubServer

PubsubServer implements the PubSub interface.

View Source
var ResultsLog = bqlog.Log{
	QueueName: AnalysisResultsQueue,
	DatasetID: "analyzer",
	TableID:   "results",
}

ResultsLog includes rows with analyzer results created when an analysis workflow is complete.

Functions

func AppID

func AppID(c context.Context) string

AppID returns the current App ID.

The dev instance name is used for local dev app servers.

func MiddlewareBase

func MiddlewareBase() router.MiddlewareChain

MiddlewareBase returns a middleware chain applied to ALL routes.

func MiddlewareForInternal

func MiddlewareForInternal() router.MiddlewareChain

MiddlewareForInternal returns a middleware chain applied to internal routes.

It assumes internal routes are protected by specifying 'login: admin' app.yaml.

func MiddlewareForREST

func MiddlewareForREST() router.MiddlewareChain

MiddlewareForREST returns a middleware chain intended for REST API routes.

It's same as MiddlewareBase, with addition of authentication based on OAuth2 access tokens. It is supposed to be used for all REST API routes.

Anonymous access is still allowed. The handlers should do authorization checks by examining auth.CurrentIdentity(ctx) (it can be identity.Anonymous).

func MiddlewareForRPC

func MiddlewareForRPC() router.MiddlewareChain

MiddlewareForRPC returns a middleware chain intended for pRPC routes.

It is identical to MiddlewareBase currently, since pRPC does its authentication (based on OAuth2 access tokens) internally.

func MiddlewareForUI

func MiddlewareForUI() router.MiddlewareChain

MiddlewareForUI returns a middleware chain intended for Web UI routes.

It's same as MiddlewareBase, with addition of authentication based on cookies. It is supposed to be used for all routes that result in HTML pages.

Anonymous access is still allowed. The handlers should do authorization checks by examining auth.CurrentIdentity(ctx) (it can be identity.Anonymous).

func NewRPCServer

func NewRPCServer() *prpc.Server

NewRPCServer returns preconfigured pRPC server that can host gRPC APIs.

Usage:

srv := NewRPCServer()
someapi.RegisterSomeAPIServer(srv, ...)
...
discovery.Enable(srv)
srv.InstallHandlers(router, MiddlewareForRPC())

func ReportServerError

func ReportServerError(c *router.Context, err error)

ReportServerError reports back a server error (http code 500).

Types

type CollectParameters

type CollectParameters struct {
	Server  string
	BuildID int64
}

CollectParameters contains the parameters for a Collect call to a TaskServerAPI.

BuildID is the int64 representation of the ID of the collected buildbucket build.

type CollectResult

type CollectResult struct {
	// State is the current status of the task (can be PENDING, SUCCESS, or FAILURE)
	State ResultState
	// BuildbucketOutput is the data value of a completed Buildbucket build,
	// which is the JSON serialization of the Results protobuf message; it
	// should be deserialized with jsonpb since fields use camelCase names.
	BuildbucketOutput string
}

CollectResult contains the return value of a Collect call to a TaskServerAPI.

type PatchDetails

type PatchDetails struct {
	GitilesHost    string
	GitilesProject string
	GerritHost     string
	GerritProject  string
	GerritChange   string
	GerritCl       string
	GerritPatch    string
}

PatchDetails contains information about the Gerrit and Gitiles patchset.

type PubSubAPI

type PubSubAPI interface {
	// Setup sets up a Pub/Sub subscription.
	//
	// The subscription will be connected to a topic derived from the instance context.
	// The topics should have the form:
	//   '/projects/tricium-dev/topics/worker-completion[-HOSTNAME]'
	// The hostname suffix should only be added for local dev server instances.
	//
	// This topic should already have been added before workflow launch.
	Setup(c context.Context) error

	// Pull pulls one pubsub message.
	Pull(c context.Context) (*pubsub.PubsubMessage, error)
}

PubSubAPI defines the interface to the pubsub server.

The interface is tuned to the needs of Tricium.

type ResultState

type ResultState int

ResultState contains the current status of a given task.

const (
	Pending ResultState = iota
	Success
	Failure
)

Constants for describing the result of a task.

type TaskServerAPI

type TaskServerAPI interface {
	// Trigger an analyzer through the external service.
	Trigger(c context.Context, params *TriggerParameters) (*TriggerResult, error)

	// Collect collects results for the analyzer.
	Collect(c context.Context, params *CollectParameters) (*CollectResult, error)
}

TaskServerAPI specifies the service API for triggering analyzers through an external service.

Only Buildbucket is supported.

type TriggerParameters

type TriggerParameters struct {
	Server         string
	Worker         *admin.Worker
	PubsubUserdata string
	Tags           []string
	Patch          PatchDetails
}

TriggerParameters contains the parameters for a Trigger call to a TaskServerAPI.

type TriggerResult

type TriggerResult struct {
	BuildID int64
}

TriggerResult contains the return value of a Trigger call to a TaskServerAPI.

BuildID is the int64 representation of the ID of the triggered buildbucket build

Directories

Path Synopsis
Package track implements shared tracking functionality for the Tricium service modules.
Package track implements shared tracking functionality for the Tricium service modules.
Package triciumtest implements common testing functionality for the Tricium service modules.
Package triciumtest implements common testing functionality for the Tricium service modules.

Jump to

Keyboard shortcuts

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