<commit_before>package newrelic

import (
	"encoding/json"
	"net/http"
	"os"
	"strings"
	"time"

	"github.com/neocortical/newrelic/model"
)

const (
	// DefaultPollInterval is the recommended poll interval for NewRelic plugins
	DefaultPollInterval = time.Minute
)

const (
	agentVersion = "0.0.1"
	apiEndpoint  = "https://platform-api.newrelic.com/platform/v1/metrics"
)

// Client encapsulates a NewRelic plugin client and all the plugins it reports
type Client struct {
	License      string
	PollInterval time.Duration
	Plugins      []*Plugin

	// HTTPClient is exposed to allow users to configure proxies, etc.
	HTTPClient *http.Client

	agent        model.Agent
	lastPollTime time.Time
	url          string
}

// AddPlugin appends a plugin to a clients list of plugins. A plugin is a "component"
// in the API call and can be configured (with a unique GUID) in the NewRelic UI.
func (c *Client) AddPlugin(p *Plugin) {
	c.Plugins = append(c.Plugins, p)
}

// New creates a new Client with the given license
func New(license string) *Client {
	result := &Client{
		License:      license,
		PollInterval: DefaultPollInterval,
		HTTPClient:   &http.Client{},
		url:          apiEndpoint,
	}

	result.agent.Version = agentVersion
	result.agent.PID = os.Getpid()
	var err error
	if result.agent.Host, err = os.Hostname(); err != nil {
		panic(err)
	}

	return result
}

func (c *Client) doSend(t time.Time) {
	request, err := c.generateRequest(t)
	if err != nil {
		Log(LogError, "ERROR: encountered error(s) creating request data: %v", err)
	}
	c.lastPollTime = t
<commit_msg>fast timeout for calls to NewRelic API<commit_after>package newrelic

import (
	"encoding/json"
	"net"
	"net/http"
	"os"
	"strings"
	"time"

	"github.com/neocortical/newrelic/model"
)

const (
	// DefaultPollInterval is the recommended poll interval for NewRelic plugins
	DefaultPollInterval = time.Minute
)

const (
	agentVersion = "0.0.1"
	apiEndpoint  = "https://platform-api.newrelic.com/platform/v1/metrics"
)

var netTransport = &http.Transport{
	Dial: (&net.Dialer{
		Timeout:   5 * time.Second,
		KeepAlive: 5 * time.Second,
	}).Dial,
	TLSHandshakeTimeout: 5 * time.Second,
}

var netClient = &http.Client{
	Timeout:   time.Second * 5,
	Transport: netTransport,
}

// Client encapsulates a NewRelic plugin client and all the plugins it reports
type Client struct {
	License      string
	PollInterval time.Duration
	Plugins      []*Plugin

	// HTTPClient is exposed to allow users to configure proxies, etc.
	HTTPClient *http.Client

	agent        model.Agent
	lastPollTime time.Time
	url          string
}

// AddPlugin appends a plugin to a clients list of plugins. A plugin is a "component"
// in the API call and can be configured (with a unique GUID) in the NewRelic UI.
func (c *Client) AddPlugin(p *Plugin) {
	c.Plugins = append(c.Plugins, p)
}

// New creates a new Client with the given license
func New(license string) *Client {
	result := &Client{
		License:      license,
		PollInterval: DefaultPollInterval,
		HTTPClient:   netClient,
		url:          apiEndpoint,
	}

	result.agent.Version = agentVersion
	result.agent.PID = os.Getpid()
	var err error
	if result.agent.Host, err = os.Hostname(); err != nil {
		panic(err)
	}

	return result
}

func (c *Client) doSend(t time.Time) {
	request, err := c.generateRequest(t)
	if err != nil {
		Log(LogError, "ERROR: encountered error(s) creating request data: %v", err)
	}
	c.lastPollTime = t

{'fraction_non_alphanumeric': 0.10629004076878276, 'fraction_numerical': 0.0034944670937682005, 'mean_word_length': 3.5197368421052633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3974223', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1152, 'n_words': 360}