Documentation ¶
Overview ¶
Package Run provides useful, yet opinionated integrations for workloads running on Cloud Run.
Index ¶
- func AddOAuth2Header(r *http.Request) *http.Request
- func AddOIDCHeader(r *http.Request, audience string) *http.Request
- func Alert(r *http.Request, message string)
- func Alertf(r *http.Request, format string, v ...any)
- func Client(name string, client any)
- func CountClients() int
- func CountConfig() int
- func Critical(r *http.Request, message string)
- func Criticalf(r *http.Request, format string, v ...any)
- func Debug(r *http.Request, message string)
- func Debugf(r *http.Request, format string, v ...any)
- func Default(r *http.Request, message string)
- func Defaultf(r *http.Request, format string, v ...any)
- func Emergency(r *http.Request, message string)
- func Emergencyf(r *http.Request, format string, v ...any)
- func Error(r *http.Request, err error)
- func Fatal(r *http.Request, err error)
- func GetConfig(key string) (string, error)
- func ID() string
- func Info(r *http.Request, message string)
- func Infof(r *http.Request, format string, v ...any)
- func JobExecution() string
- func JobName() string
- func JobTaskAttempt() int
- func JobTaskCount() int
- func JobTaskIndex() int
- func KNativeService() (knative.Service, error)
- func LazyClient(name string, init func())
- func ListClientNames() []string
- func ListConfigKeys() []string
- func LoadAllConfig()
- func LoadConfig(env string) (string, error)
- func Log(r *http.Request, severity string, message string)
- func Logf(r *http.Request, severity string, format string, v ...any)
- func Name() string
- func Notice(r *http.Request, message string)
- func Noticef(r *http.Request, format string, v ...any)
- func ProjectID() string
- func ProjectNumber() string
- func PutConfig(key string, val string)
- func Region() string
- func ResetClients()
- func ResetConfig()
- func ResetInstance()
- func ServeGRPC(shutdown func(context.Context), server *grpc.Server) error
- func ServeHTTP(shutdown func(context.Context), server *http.Server) error
- func ServiceAccountAccessToken() string
- func ServiceAccountEmail() string
- func ServiceAccountIdentityToken(audience string) string
- func ServiceName() string
- func ServicePort() string
- func ServiceRevision() string
- func URL() string
- func UseClient[T any](name string, client T) (T, error)
- func Warning(r *http.Request, message string)
- func Warningf(r *http.Request, format string, v ...any)
- type LogEntry
- type SourceLocation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddOAuth2Header ¶ added in v0.4.1
AddOAuth2Header injects an `Authorization` header with a valid access token for the configured service account into the supplied HTTP request and returns it.
func AddOIDCHeader ¶ added in v0.4.1
AddOIDCHeader injects an `Authorization` header with a valid identity token for the configured service account into the supplied HTTP request and returns it.
func Alertf ¶ added in v0.3.0
Alertf logs a message with ALERT severity and message interpolation/formatting
func CountClients ¶ added in v0.5.1
func CountClients() int
CountClients returns number of stored clients.
func CountConfig ¶ added in v0.5.1
func CountConfig() int
CountConfig returns number of stored config elements.
func Criticalf ¶ added in v0.3.0
Criticalf logs a message with CRITICAL severity and message interpolation/formatting
func Debugf ¶ added in v0.3.0
Debugf logs a message with DEBUG severity and message interpolation/formatting
func Defaultf ¶ added in v0.3.0
Defaultf logs a message with DEFAULT severity and message interpolation/formatting
func Emergencyf ¶ added in v0.3.0
Emergencyf logs a message with EMERGENCY severity and message interpolation/formatting
func GetConfig ¶ added in v0.3.0
GetConfig retrieves a value for a key from the global config store.
func ID ¶ added in v0.3.0
func ID() string
ID returns the unique instance ID of the Cloud Run instance serving the running job or service by referring to the metadata server.
If the current process does not seem to be hosted on Cloud Run, it will simply return `000000`.
func Infof ¶ added in v0.3.0
Infof logs a message with INFO severity and message interpolation/formatting
func JobExecution ¶ added in v0.3.0
func JobExecution() string
JobExecution returns the execution identifier of the currently running Cloud Run job by looking up the `CLOUD_RUN_EXECUTION` environment variable.
func JobName ¶ added in v0.3.0
func JobName() string
JobName returns the name of the currently running Cloud Run job by looking up the `CLOUD_RUN_JOB` environment variable.
If the current process does not seem to be hosted on Cloud Run, it will simply return `local`.
func JobTaskAttempt ¶ added in v0.3.0
func JobTaskAttempt() int
JobTaskAttempt looks up and returns the current task attempt for the running Cloud Run job.
If the current process does not seem to be hosted on Cloud Run, it will sumply return `-1`.
func JobTaskCount ¶ added in v0.3.0
func JobTaskCount() int
JobTaskCount looks up and returns the current task count for the running Cloud Run job.
If the current process does not seem to be hosted on Cloud Run, it will sumply return `-1`.
func JobTaskIndex ¶ added in v0.3.0
func JobTaskIndex() int
JobTaskIndex looks up and returns the current task index for the running Cloud Run job.
If the current process does not seem to be hosted on Cloud Run, it will sumply return `-1`.
func KNativeService ¶ added in v0.6.4
KNativeService loads and returns a KNative Serving representation of the current service. Requires at least roles/run.Viewer on itself.
func LazyClient ¶ added in v0.6.0
func LazyClient(name string, init func())
LazyClient registers an uninitialized client name with an initialization function. The init func should call Client() with the initialized client.
func ListClientNames ¶ added in v0.3.0
func ListClientNames() []string
ListClientNames returns a list of all available keys store in the global clients store.
func ListConfigKeys ¶ added in v0.3.0
func ListConfigKeys() []string
ListConfigKeys returns a list of all currently available keys in the global config store.
func LoadAllConfig ¶ added in v0.6.3
func LoadAllConfig()
LoadAllConfig loads all available environment variables and puts it in the config store.
func LoadConfig ¶ added in v0.3.0
LoadConfig lookups the named environment variable, puts it's value into the global config store and returns the value.
func Name ¶ added in v0.3.0
func Name() string
Name returns a preferred name for the currently running Cloud Run service or job. This will be either the service or job name or simply 'local'.
func Noticef ¶ added in v0.3.0
Noticef logs a message with NOTICE severity and message interpolation/formatting
func ProjectID ¶
func ProjectID() string
ProjectID attempts to resolve the alphanumeric Google Cloud project ID that is hosting the current Cloud Run instance.
It loosely does so by looking up the following established precedence: - The environment variable `GOOGLE_CLOUD_PROJECT` - Querying the metadata server - Simply returning `local`
func ProjectNumber ¶
func ProjectNumber() string
ProjectNumber looks up the numeric project number of the current Google Cloud project hosting the Cloud Run instance.
If the current process does not seem to be hosted on Cloud Run, it will return `000000000000`.
func Region ¶ added in v0.3.0
func Region() string
Region looks up the actively serving region for this Cloud Run service.
If the current process does not seem to be hosted on Cloud Run, it will return `local`.
func ResetClients ¶ added in v0.3.0
func ResetClients()
ResetClients deletes all previously configured clients.
func ResetConfig ¶ added in v0.3.0
func ResetConfig()
ResetConfig deletes all previously configured config.
func ResetInstance ¶ added in v0.3.0
func ResetInstance()
ResetInstance resets the cached metadata of this instance
func ServeGRPC ¶ added in v0.4.0
ServeGRPC starts the GRPC server, listens and serves requests
It also traps SIGINT and SIGTERM. Both signals will cause a graceful shutdown of the GRPC server and executes the user supplied shutdown func.
func ServeHTTP ¶ added in v0.4.0
ServeHTTP starts the HTTP server, listens and serves requests
It also traps SIGINT and SIGTERM. Both signals will cause a graceful shutdown of the HTTP server and executes the user supplied shutdown func.
func ServiceAccountAccessToken ¶ added in v0.4.1
func ServiceAccountAccessToken() string
ServiceAccountAccessToken looks up and returns a fresh OAuth2 access token for the service account configured for this Cloud Run instance.
If the current process does not seem to be hosted on Cloud Run, it will return `local-access-token`.
func ServiceAccountEmail ¶ added in v0.3.0
func ServiceAccountEmail() string
ServiceAccountEmail looks up and returns the email of the service account configured for this Cloud Run instance.
If the current process does not seem to be hosted on Cloud Run, it will return `local@localhost.com`.
func ServiceAccountIdentityToken ¶ added in v0.4.1
ServiceAccountIdentityToken attempts to mint an OIDC Identity Token for the specified `audience` using the metadata server.
If the current process does not seem to be hosted on Cloud Run, it will return `local-identity-token`.
func ServiceName ¶ added in v0.3.0
func ServiceName() string
ServiceName returns the name of the currently running Cloud Run service by looking up the `K_SERVICE` environment variable.
If the current process does not seem to be hosted on Cloud Run, it will simply return `local`.
func ServicePort ¶ added in v0.3.0
func ServicePort() string
ServicePort looks up and returns the configured service `$PORT` for this Cloud Run service.
If the current process does not seem to be hosted on Cloud Run, it will return the default value `8080`.
func ServiceRevision ¶ added in v0.3.0
func ServiceRevision() string
ServiceRevision returns the revision identifier of the currently running Cloud Run service by looking up the `K_REVISION` environment variable.
If the current process does not seem to be hosted on Cloud Run, it will return a deterministic identifier in the form of `<SERVICE_NAME>-00001-xxx`.
func URL ¶ added in v0.6.11
func URL() string
URL infers the URL with which this service will be addressable. This will either be 'http://localhost:8080' or the deterministic URL provided by Cloud Run
func UseClient ¶ added in v0.5.0
UseClient is intended to retrieve a pointer to a client for a given key name. It requires the name of a stored client and a nil pointer of it's type. NOTE: maybe this shouldn't return T, just error...
Types ¶
type LogEntry ¶
type LogEntry struct { Message string `json:"message"` Severity string `json:"severity,omitempty"` // Trace is the trace ID of the log message which will be propagated into // Cloud Trace. Trace string `json:"logging.googleapis.com/trace,omitempty"` // SourceLocation holds the location within the source where the log message // was generated. SourceLocation *SourceLocation `json:"logging.googleapis.com/sourceLocation,omitempty"` // Component is the name of the service or job that produces the log entry. Component string `json:"component,omitempty"` }
LogEntry is the structured version of a single log entry intended to be stored in Google Cloud Logging in JSON-serialized form.
type SourceLocation ¶ added in v0.4.0
type SourceLocation struct { File string `json:"file,omitempty"` Function string `json:"function,omitempty"` Line string `json:"line,omitempty"` }
SourceLocation is the structured version of a location in the source code (at compile time) which emits a log entry (at runtime). It is intended to be embedded in a run.LogEntry in JSON-serialized form.