Example #1
0
// Returns a thread-compatible implementation of GCM interactions.
func NewCore() (*GcmCore, error) {
	token, err := gce.NewAuthTokenProvider(GCMAuthScope)
	if err != nil {
		return nil, err
	}

	// Detect project.
	project, err := metadata.ProjectID()
	if err != nil {
		return nil, err
	}

	core := &GcmCore{
		token:           token,
		project:         project,
		exportedMetrics: make(map[string]metricDescriptor),
		lastValue:       gcstore.New(time.Hour),
	}

	// Wait for an initial token.
	_, err = core.token.WaitForToken()
	if err != nil {
		return nil, err
	}

	if err := core.listMetrics(); err != nil {
		return nil, err
	}

	return core, nil
}
Example #2
0
// Returns an implementation of a Google Cloud Logging (GCL) sink.
func new() (sink_api.ExternalSink, error) {
	token, err := gce.NewAuthTokenProvider(GCLAuthScope)
	if err != nil {
		return nil, err
	}

	// Detect project ID
	projectId, err := metadata.ProjectID()
	if err != nil {
		return nil, err
	}
	glog.Infof("Project ID for GCL sink is: %q\r\n", projectId)

	impl := &gclSink{
		token:      token,
		projectId:  projectId,
		httpClient: &http.Client{},
	}

	return impl, nil
}