<commit_before>package events

import (
	"bytes"
	"encoding/json"
	"errors"
	"log"
	"net/http"
)

var (
	TutumEndpoint string
	TutumAuth     string
)

func SendContainerEvent(event Event) {
	data, err := json.Marshal(event)
	if err != nil {
		log.Printf("Cannot marshal the posting data: %s\n", event)
	}

	log.Printf("Sending container event: %s on %s \n", event.Status, event.ID)
	if err := sendData(TutumEndpoint, data); err != nil {
		log.Printf("Error when Posting %s:%s\n", data, err.Error())
	}
}

func sendData(url string, data []byte) error {
	client := &http.Client{}
	req, err := http.NewRequest("POST", url, bytes.NewReader(data))
	if err != nil {
		SendError(err, "Failed to create http.NewRequest", nil)
		return err
	}
	req.Header.Add("Authorization", TutumAuth)
	resp, err := client.Do(req)
	if err != nil {
		extra := map[string]interface{}{"data": string(data)}
		SendError(err, "Failed to POST the http request", extra)
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 200, 201, 202:
		return nil
	default:
		extra := map[string]interface{}{"data": string(data)}
		SendError(errors.New(resp.Status), "http error", extra)
		return errors.New(resp.Status)
	}
}<commit_msg>mute http 404 on sentry<commit_after>package events

import (
	"bytes"
	"encoding/json"
	"errors"
	"log"
	"net/http"
)

var (
	TutumEndpoint string
	TutumAuth     string
)

func SendContainerEvent(event Event) {
	data, err := json.Marshal(event)
	if err != nil {
		log.Printf("Cannot marshal the posting data: %s\n", event)
	}

	log.Printf("Sending container event: %s on %s \n", event.Status, event.ID)
	if err := sendData(TutumEndpoint, data); err != nil {
		log.Printf("Error when Posting %s:%s\n", data, err.Error())
	}
}

func sendData(url string, data []byte) error {
	client := &http.Client{}
	req, err := http.NewRequest("POST", url, bytes.NewReader(data))
	if err != nil {
		SendError(err, "Failed to create http.NewRequest", nil)
		return err
	}
	req.Header.Add("Authorization", TutumAuth)
	resp, err := client.Do(req)
	if err != nil {
		extra := map[string]interface{}{"data": string(data)}
		SendError(err, "Failed to POST the http request", extra)
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 200, 201, 202, 204:
		return nil
	case 404:
		return errors.New(resp.Status)
	default:
		extra := map[string]interface{}{"data": string(data)}
		SendError(errors.New(resp.Status), "http error", extra)
		return errors.New(resp.Status)
	}
}
{'fraction_non_alphanumeric': 0.15520707679935666, 'fraction_numerical': 0.010856453558504222, 'mean_word_length': 4.3049040511727075, 'pattern_counts': {'":': 4, '<': 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': '1829899', 'n_tokens_mistral': 941, 'n_tokens_neox': 887, 'n_words': 239}