Пример #1
0
// AddSample adds a sample to the local cache ready to be sent to central using SendSamples.
func (s *Suggestion) AddSample(sampleType, data string) {
	ID, err := shared.SecureRandomString(32)
	if err != nil {
		panic("could not generate random number")
	}
	ss := sample{
		id:         ID,
		sampleType: sampleType,
		data:       data,
		createdAt:  time.Now(),
	}
	modifySuggestion <- addSample(*s, ss)
}
Пример #2
0
// NewSuggestion creates a new local suggestion
func NewSuggestion(URL string) Suggestion {
	ID, err := shared.SecureRandomString(32)
	if err != nil {
		panic("could not generate random number")
	}
	item := Suggestion{
		ID:        ID,
		URL:       URL,
		CreatedAt: time.Now(),
		samples:   make([]sample, 0),
	}
	addSuggestion <- item
	return item
}
Пример #3
0
// NewDebugResponse creates a filled DebugResponse struct
func NewDebugResposne(version string, config interface{}) *DebugResponse {
	ID, err := shared.SecureRandomString(12)
	if err != nil {
		panic("could not generate random number")
	}
	response := &DebugResponse{
		Header: DebugHeader{
			Cmd:       filepath.Base(os.Args[0]),
			ID:        ID,
			Version:   version,
			CreatedAt: time.Now(),
			OS:        runtime.GOOS,
			Arch:      runtime.GOARCH,
			GoVersion: runtime.Version(),
		},
		Config: config,
	}

	getProfile := func(name string) []string {
		buf := bytes.NewBuffer(nil)
		err := pprof.Lookup(name).WriteTo(buf, 2)
		if err != nil {
			lg.Errorln(err)
		} else {
			return strings.Split(
				buf.String(),
				"\n")
		}
		return []string{}
	}

	response.Heap = getProfile("heap")
	response.GoRoutines = getProfile("goroutine")
	response.ThreadCreate = getProfile("threadcreate")
	response.Block = getProfile("block")
	// memlog should be last so that it can catch errors up to the point of
	// collection.
	response.Log = lg.Memlog()

	if PublicKey != "" {
		response.Encrypt(PublicKey)
	} else {
		lg.Warningln("PublicKey not set, exporting unencrypted debug log")
	}

	return response

}
Пример #4
0
func (s *sessionTokenStore) New(URL string) shared.SuggestionToken {
	idstr, err := shared.SecureRandomString(32)
	if err != nil {
		panic(err)
	}
	id := shared.SuggestionToken(idstr)
	s.Lock()
	s.sessions[id] = tokenData{
		ID:        id,
		CreatedAt: time.Now(),
		URL:       URL,
	}
	s.Unlock()
	tokenSessionsActive.Add(1)
	tokenSessionsTotal.Add(1)
	return id
}