Skip to content

Commit

Permalink
Added an error handler (#243)
Browse files Browse the repository at this point in the history
* added an error handler

* added an error handler
increased version
  • Loading branch information
kochetovd authored Dec 20, 2023
1 parent 0d98b5f commit 9bd5d46
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
ReleemAgentVersion = "1.10.0.4"
ReleemAgentVersion = "1.11.0"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion current_version_agent
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0.4
1.11.0
6 changes: 3 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
# install.sh - Version 1.10.0.4
# install.sh - Version 1.11.0
# (C) Releem, Inc 2022
# All rights reserved

# Releem installation script: install and set up the Releem Agent on supported Linux distributions
# using the package manager.

set -e
install_script_version=1.10.0.4
install_script_version=1.11.0
logfile="releem-install.log"

WORKDIR="/opt/releem"
Expand Down Expand Up @@ -55,7 +55,7 @@ function releem_update() {
$sudo_cmd chmod 755 $WORKDIR/mysqlconfigurer.sh $WORKDIR/releem-agent
$sudo_cmd $WORKDIR/releem-agent start || true
$sudo_cmd $WORKDIR/releem-agent -f

echo
echo
echo -e "Releem Agent updated successfully."
Expand Down
4 changes: 2 additions & 2 deletions mysqlconfigurer.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# mysqlconfigurer.sh - Version 1.10.0.4
# mysqlconfigurer.sh - Version 1.11.0
# (C) Releem, Inc 2022
# All rights reserved

Expand All @@ -12,7 +12,7 @@ MYSQLTUNER_REPORT=$MYSQLCONFIGURER_PATH"mysqltunerreport.json"
RELEEM_MYSQL_VERSION=$MYSQLCONFIGURER_PATH"mysql_version"
MYSQLCONFIGURER_CONFIGFILE="${MYSQLCONFIGURER_PATH}${MYSQLCONFIGURER_FILE_NAME}"
MYSQL_MEMORY_LIMIT=0
VERSION="1.10.0.4"
VERSION="1.11.0
RELEEM_INSTALL_PATH=$MYSQLCONFIGURER_PATH"install.sh"
logfile="releem-mysqlconfigurer.log"
Expand Down
4 changes: 4 additions & 0 deletions repeater/releemConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricCont
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return nil, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())
client := http.Client{
Expand All @@ -45,13 +46,15 @@ func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricCont
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return nil, err
}
defer res.Body.Close()
repeater.logger.Println(" * Downloading recommended MySQL configuration from Releem Cloud Platform...")

body_res, err := io.ReadAll(res.Body)
if err != nil {
repeater.logger.Error("Response: error read body request: ", err)
return nil, err
}
if res.StatusCode != 200 {
repeater.logger.Println("Response: status code: ", res.StatusCode)
Expand All @@ -62,6 +65,7 @@ func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricCont
err = os.WriteFile(context.GetReleemConfDir()+"/z_aiops_mysql.cnf", body_res, 0644)
if err != nil {
repeater.logger.Error("WriteFile: Error write to file: ", err)
return nil, err
}
repeater.logger.Println("1. Recommended MySQL configuration downloaded to ", context.GetReleemConfDir())
repeater.logger.Println("2. To check MySQL Performance Score please visit https://app.releem.com/dashboard?menu=metrics")
Expand Down
2 changes: 2 additions & 0 deletions repeater/releemEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (repeater ReleemEventsRepeater) ProcessMetrics(context m.MetricContext, met
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return nil, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())

Expand All @@ -47,6 +48,7 @@ func (repeater ReleemEventsRepeater) ProcessMetrics(context m.MetricContext, met
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return nil, err
}
repeater.logger.Debug("Response: status code: ", res)
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion repeater/releemMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (repeater ReleemMetricsRepeater) ProcessMetrics(context m.MetricContext, me
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return nil, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())

Expand All @@ -45,10 +46,15 @@ func (repeater ReleemMetricsRepeater) ProcessMetrics(context m.MetricContext, me
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return nil, err
}
repeater.logger.Debug("Response: status code: ", res.StatusCode)
defer res.Body.Close()
body_res, _ := io.ReadAll(res.Body)
body_res, err := io.ReadAll(res.Body)
if err != nil {
repeater.logger.Error("Response: error read body request: ", err)
return nil, err
}
repeater.logger.Debug("Response: body:\n", string(body_res))
return string(body_res), err
}
Expand Down
20 changes: 14 additions & 6 deletions tasks/taskGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ReleemTasksRepeater struct {
}

func (repeater ReleemTasksRepeater) ProcessMetrics(context m.MetricContext, metrics m.Metrics) (interface{}, error) {
result_data := m.Task{}
e, _ := json.Marshal(metrics)
bodyReader := strings.NewReader(string(e))
repeater.logger.Debug("Result Send data: ", string(e))
Expand All @@ -34,6 +35,7 @@ func (repeater ReleemTasksRepeater) ProcessMetrics(context m.MetricContext, metr
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return result_data, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())
client := http.Client{
Expand All @@ -42,20 +44,26 @@ func (repeater ReleemTasksRepeater) ProcessMetrics(context m.MetricContext, metr
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return result_data, err
}
defer res.Body.Close()

body_res, err := io.ReadAll(res.Body)
if err != nil {
repeater.logger.Error("Response: error read body request: ", err)
return result_data, err
}
repeater.logger.Debug("Response: status code: ", res.StatusCode, api_domain)
repeater.logger.Debug("Response: body:\n", string(body_res))
result_data := m.Task{}
err1 := json.Unmarshal(body_res, &result_data)
if res.StatusCode != 200 {
repeater.logger.Println("Response: status code: ", res.StatusCode)
repeater.logger.Println("Response: body:\n", string(body_res))
} else {
repeater.logger.Debug("Response: status code: ", res.StatusCode)
repeater.logger.Debug("Response: body:\n", string(body_res))
err := json.Unmarshal(body_res, &result_data)

if err1 != nil {
repeater.logger.Error(err1)
if err != nil {
repeater.logger.Error(err)
}
}
return result_data, err

Expand Down
2 changes: 2 additions & 0 deletions tasks/taskSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (repeater ReleemTaskSetRepeater) ProcessMetrics(context m.MetricContext, me
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return nil, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())

Expand All @@ -46,6 +47,7 @@ func (repeater ReleemTaskSetRepeater) ProcessMetrics(context m.MetricContext, me
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return nil, err
}
repeater.logger.Debug("Response: status code: ", res)
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions tasks/taskStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (repeater ReleemTaskStatusRepeater) ProcessMetrics(context m.MetricContext,
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
repeater.logger.Error("Request: could not create request: ", err)
return nil, err
}
req.Header.Set("x-releem-api-key", context.GetApiKey())

Expand All @@ -43,6 +44,7 @@ func (repeater ReleemTaskStatusRepeater) ProcessMetrics(context m.MetricContext,
res, err := client.Do(req)
if err != nil {
repeater.logger.Error("Request: error making http request: ", err)
return nil, err
}
if res.StatusCode != 201 {
repeater.logger.Println("Response: status code: ", res.StatusCode)
Expand Down

0 comments on commit 9bd5d46

Please sign in to comment.