Failed posts and failover for export loggers

This commit is contained in:
adi
2022-06-28 16:56:10 +03:00
committed by Dan Christian Bogos
parent f562de49df
commit c22f43c788
13 changed files with 229 additions and 84 deletions

View File

@@ -1731,8 +1731,8 @@ const (
const (
LevelCfg = "level"
KafkaConnCfg = "*kafka_conn"
KafkaTopicCfg = "*kafka_topic"
KafkaConnCfg = "kafka_conn"
KafkaTopicCfg = "kafka_topic"
)
const (

View File

@@ -486,6 +486,16 @@ func ToJSON(v interface{}) string {
return string(b)
}
func ToUnescapedJSON(value interface{}) (bts []byte, err error) {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
if err = enc.Encode(value); err != nil {
return
}
return buf.Bytes(), err
}
// Used as generic function logic for various fields
// Attributes

View File

@@ -65,6 +65,7 @@ var (
DispatcherErrorPrefix = "DISPATCHER_ERROR"
RateSErrPrfx = "RATES_ERROR"
AccountSErrPrfx = "ACCOUNTS_ERROR"
ErrLoggerChanged = errors.New("LOGGER_CHANGED")
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
ErrNoDatabaseConn = errors.New("NO_DATABASE_CONNECTION")
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")

70
utils/failover_export.go Normal file
View File

@@ -0,0 +1,70 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package utils
import (
"encoding/gob"
"fmt"
"os"
"path/filepath"
)
type FailoverPoster struct {
MessageProvider
}
func NewFailoverPoster( /*addMsg *MessageProvider*/ ) *FailoverPoster {
return new(FailoverPoster)
}
func (fldPst *FailoverPoster) AddMessage(failedPostDir, kafkaConn,
kafkaTopic string, content interface{}) (err error) {
filePath := filepath.Join(failedPostDir, kafkaTopic+PipeSep+MetaKafka+GOBSuffix)
var fileOut *os.File
if _, err = os.Stat(filePath); os.IsNotExist(err) {
fileOut, err = os.Create(filePath)
if err != nil {
return fmt.Errorf(fmt.Sprintf("<Kafka> failed to write logs to file <%s> because <%s>", filePath, err))
}
} else {
fileOut, err = os.OpenFile(filePath, os.O_RDWR|os.O_APPEND, 0755)
if err != nil {
return err
}
}
enc := gob.NewEncoder(fileOut)
if err = enc.Encode(content); err != nil {
return err
}
fileOut.Close()
return
}
type MessageProvider interface {
GetContent() string
GetMeta() string
}
func (fldPst *FailoverPoster) GetContent() string {
return EmptyString
}
func (fldPst *FailoverPoster) GetMeta() string {
return EmptyString
}