Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix grafana metric bugs #88

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions panel/handlers/advertiserhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"YellowBloomKnapsack/mini-yektanet/common/models"
"YellowBloomKnapsack/mini-yektanet/panel/database"
"YellowBloomKnapsack/mini-yektanet/panel/grafana"
// "github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -77,8 +76,6 @@ func AdvertiserPanel(c *gin.Context) {
"TotalPages": totalPages,
"CurrentPage": page + 1,
})

grafana.TotalAdvertiserBalance.Set(float64(advertiser.Balance))
}

func AddFunds(c *gin.Context) {
Expand Down Expand Up @@ -146,6 +143,7 @@ func AddFunds(c *gin.Context) {

c.Redirect(http.StatusSeeOther, fmt.Sprintf("/advertiser/%s/panel", advertiserUserName))

grafana.TotalAdvertiserBalance.Add(float64(transaction.Amount))
grafana.TransactionCount.WithLabelValues("add_funds_success").Inc()
}

Expand Down Expand Up @@ -307,6 +305,7 @@ func HandleEditAd(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid bid amount"})
return
}
oldBid := ad.Bid
ad.Bid = bid

// Handle image upload if a new image is provided
Expand Down Expand Up @@ -340,6 +339,7 @@ func HandleEditAd(c *gin.Context) {
return
}

grafana.TotalAdvertiserBalance.Add(float64(ad.Bid-oldBid))
c.Redirect(http.StatusSeeOther, "/advertiser/"+username+"/panel")
}

Expand Down
8 changes: 2 additions & 6 deletions panel/handlers/publisherhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func PublisherPanel(c *gin.Context) {
script := fmt.Sprintf("<script> %s </script>",
generateScript(publisher.ID))

// script := fmt.Sprintf("<script src='%s:%s/js/script.js'></script>",
// os.Getenv("HOSTNAME"),
// os.Getenv("PUBLISHER_WEBSITE_PORT"))

yektanetPortionString := os.Getenv("YEKTANET_PORTION")

// Convert the value to an integer
Expand Down Expand Up @@ -123,8 +119,8 @@ func WithdrawPublisherBalance(c *gin.Context) {
})

// update grafana metrics
grafana.TotalPublisherBalance.Set(float64(publisher.Balance))
grafana.TransactionCount.WithLabelValues("withdraw_success_failure").Inc()
grafana.TotalPublisherBalance.Add(-float64(transaction.Amount))
grafana.TransactionCount.WithLabelValues("withdraw_balance_success").Inc()
}

func prepareChartData(interactions []models.AdsInteraction, yektanetPortion int) map[string]interface{} {
Expand Down
1 change: 0 additions & 1 deletion panel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func main() {
advertiser.POST("/:username/toggle-ad", handlers.ToggleAd)
advertiser.GET("/:username/ad-report/:id", handlers.AdReport)
advertiser.POST("/:username/edit-ad", handlers.HandleEditAd)

}

publisher := r.Group("/publisher")
Expand Down
Loading