Skip to content

Commit

Permalink
Add verbose logs
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Dec 30, 2024
1 parent f22b465 commit 4678e3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions exporter/clickhouselogsexporter/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
)

func UsageExporter(metrics []*metricdata.Metric, id uuid.UUID) (map[string]usage.Usage, error) {
fmt.Println("usage exporter called in clickhouse logsexporter")
data := map[string]usage.Usage{}
for _, metric := range metrics {
if !strings.Contains(metric.Descriptor.Name, SigNozLogsCount) && !strings.Contains(metric.Descriptor.Name, SigNozLogsBytes) {
Expand All @@ -56,6 +57,7 @@ func UsageExporter(metrics []*metricdata.Metric, id uuid.UUID) (map[string]usage
exporterIndex := usage.GetIndexOfLabel(metric.Descriptor.LabelKeys, usage.ExporterIDKey)
tenantIndex := usage.GetIndexOfLabel(metric.Descriptor.LabelKeys, usage.TenantKey)
if exporterIndex == -1 || tenantIndex == -1 {
fmt.Println("error in usage parser failed to get index of labels", metric.Descriptor.Name, metric.Descriptor.LabelKeys)
return nil, fmt.Errorf("usage: failed to get index of labels")
}

Expand Down Expand Up @@ -91,5 +93,8 @@ func UsageExporter(metrics []*metricdata.Metric, id uuid.UUID) (map[string]usage
}
}
}
for _, d := range data {
fmt.Println("data.count, data.size, data.timestamp", d.Count, d.Size, d.TimeStamp)
}
return data, nil
}
5 changes: 5 additions & 0 deletions usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (e *UsageCollector) Start() error {
}

func (c *UsageCollector) Stop() error {
fmt.Println("stopping usage collector")
c.ir.Stop()
c.ir.Flush()
return nil
Expand All @@ -81,23 +82,27 @@ func (c *UsageCollector) Stop() error {
func (e *UsageCollector) ExportMetrics(ctx context.Context, metrics []*metricdata.Metric) error {
usages, err := e.usageParser(metrics, e.exporterID)
if err != nil {
fmt.Println("error in usage parser", err)
return err
}
time := time.Now()
for tenant, usage := range usages {
usage.TimeStamp = time
usageBytes, err := json.Marshal(usage)
if err != nil {
fmt.Println("error in marshaling usage", err)
return err
}
encryptedData, err := Encrypt([]byte(e.exporterID.String())[:32], usageBytes)
if err != nil {
fmt.Println("error in encrypting usage", err)
return err
}

// insert everything as a new row
err = e.db.Exec(ctx, fmt.Sprintf("insert into %s.%s values ($1, $2, $3, $4, $5)", e.dbName, e.distributedTableName), tenant, CollectorID.String(), e.exporterID.String(), time, string(encryptedData))
if err != nil {
fmt.Println("error in inserting usage", err)
return err
}
}
Expand Down

0 comments on commit 4678e3b

Please sign in to comment.