<commit_before>package main

import (
	"fmt"
	"time"

	"github.com/koding/kite"
	"github.com/koding/kite/protocol"
	"github.com/koding/kloud"
)

// Kloud represents a remote kloud instance
type Kloud struct {
	client *kite.Client
}

// Kloud returns a new connected kloud instance. The kloud is ready to use.
// It's connected and will redial if there is any disconnections.
func NewKloud(k *kite.Kite) (*Kloud, error) {
	kontrolQuery := protocol.KontrolQuery{
		Username:    "koding",
		Environment: "vagrant",
		Name:        "kloud",
	}

	timeout := time.After(time.Minute)

	k.Log.Info("Querying for Kloud: %+v", kontrolQuery)
	for {
		select {
		case <-time.Tick(time.Second * 2):
			kites, err := k.GetKites(kontrolQuery)
			if err != nil {
				// still not up, try again until the kite is ready
				continue
			}

			remoteKite := kites[0]

			connected, err := remoteKite.DialForever()
			if err != nil {
				return nil, err
			}

			select {
			case <-connected:
			case <-time.After(time.Minute):
				return nil, kloud.NewError(kloud.ErrNoKiteConnection)
			}

			// Kloud connection is ready now
			return &Kloud{
				client: remoteKite,
			}, nil
		case <-timeout:
			return nil, fmt.Errorf("timeout while connection for kite")
		}
	}
}

// Report reports machine and usage metrics to kloud instance.
func (k *Kloud) Report() error {
	// update information before we send it
	usg.Update()

	fmt.Printf("repoting usage %+v\n", usg)
	resp, err := k.client.Tell("report", usg)
	if err != nil {
		return err
	}

	fmt.Printf("kloud response: %+v\n", resp.MustString())
	return nil
}<commit_msg>kloud: move report to koding provider<commit_after>package main

import (
	"fmt"
	"time"

	"github.com/koding/kite"
	"github.com/koding/kite/protocol"
	"github.com/koding/kloud"
)

// Kloud represents a remote kloud instance
type Kloud struct {
	client *kite.Client
}

// Kloud returns a new connected kloud instance. The kloud is ready to use.
// It's connected and will redial if there is any disconnections.
func NewKloud(k *kite.Kite) (*Kloud, error) {
	kontrolQuery := protocol.KontrolQuery{
		Username:    "koding",
		Environment: "vagrant",
		Name:        "kloud",
	}

	timeout := time.After(time.Minute)

	k.Log.Info("Querying for Kloud: %+v", kontrolQuery)
	for {
		select {
		case <-time.Tick(time.Second * 2):
			kites, err := k.GetKites(kontrolQuery)
			if err != nil {
				// still not up, try again until the kite is ready
				continue
			}

			remoteKite := kites[0]

			connected, err := remoteKite.DialForever()
			if err != nil {
				return nil, err
			}

			select {
			case <-connected:
			case <-time.After(time.Minute):
				return nil, kloud.NewError(kloud.ErrNoKiteConnection)
			}

			// Kloud connection is ready now
			return &Kloud{
				client: remoteKite,
			}, nil
		case <-timeout:
			return nil, fmt.Errorf("timeout while connection for kite")
		}
	}
}

// Report reports machine and usage metrics to kloud instance.
func (k *Kloud) Report() error {
	// update information before we send it
	usg.Update()

	fmt.Printf("repoting usage %+v\n", usg)
	_, err := k.client.Tell("report", usg)
	return err
}
{'fraction_non_alphanumeric': 0.12711593740019164, 'fraction_numerical': 0.0012775471095496647, 'mean_word_length': 3.2040268456375838, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6448109', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1094, 'n_words': 319}