<commit_before>// Copyright 2017 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

type tsuruClient struct {
	addr       string
	token      string
	httpClient *http.Client
}

type unitCount struct {
	app   string
	pool  string
	team  string
	count int
}

type nodeResult struct {
	Nodes []node
}

type node struct {
	Metadata nodeMetadata
}
type nodeMetadata struct {
	Pool string
}

type app struct {
	Name  string
	Units []unit
	Pool  string
}

type unit struct {
	Status string
}

func newClient(addr, token string) *tsuruClient {
	return &tsuruClient{addr: addr, token: token, httpClient: &http.Client{}}
}

func (c *tsuruClient) fetchUnitsCount() ([]unitCount, error) {
	var apps []app
	err := c.fetchList("apps", &apps)
	if err != nil {
		return nil, err
	}
	var counts []unitCount
	for _, a := range apps {
		var count int
		for _, u := range a.Units {
			if u.Status == "started" || u.Status == "error" {
				count++
			}
		}
		counts = append(counts, unitCount{app: a.Name, pool: a.Pool, count: count})
	}
	return counts, nil
}

func (c *tsuruClient) fetchNodesCount() (map[string]int, error) {
	var result nodeResult
	err := c.fetchList("node", &result)
	if err != nil {
		return nil, err
	}<commit_msg>adds client timeout<commit_after>// Copyright 2017 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

type tsuruClient struct {
	addr       string
	token      string
	httpClient *http.Client
}

type unitCount struct {
	app   string
	pool  string
	team  string
	count int
}

type nodeResult struct {
	Nodes []node
}

type node struct {
	Metadata nodeMetadata
}
type nodeMetadata struct {
	Pool string
}

type app struct {
	Name  string
	Units []unit
	Pool  string
}

type unit struct {
	Status string
}

func newClient(addr, token string) *tsuruClient {
	return &tsuruClient{addr: addr, token: token, httpClient: &http.Client{Timeout: 10 * time.Second}}
}

func (c *tsuruClient) fetchUnitsCount() ([]unitCount, error) {
	var apps []app
	err := c.fetchList("apps", &apps)
	if err != nil {
		return nil, err
	}
	var counts []unitCount
	for _, a := range apps {
		var count int
		for _, u := range a.Units {
			if u.Status == "started" || u.Status == "error" {
				count++
			}
		}
		counts = append(counts, unitCount{app: a.Name, pool: a.Pool, count: count})
	}
	return counts, nil
}

func (c *tsuruClient) fetchNodesCount() (map[string]int, error) {
	var result nodeResult
	err := c.fetchList("node", &result)
	if err != nil {
		return nil, err
	}
{'fraction_non_alphanumeric': 0.11512089498376038, 'fraction_numerical': 0.003608805485384338, 'mean_word_length': 3.463768115942029, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2507354', 'n_tokens_mistral': 990, 'n_tokens_neox': 956, 'n_words': 327}