Giter VIP home page Giter VIP logo

Comments (1)

asobti avatar asobti commented on August 29, 2024

I don't think this is an issue. I verified this with alerts and it works correctly.

Verification script:

package main

import (
	"fmt"
	"github.com/spaceapegames/go-wavefront"
	"time"
)

func create(alertClient *wavefront.Alerts) (*wavefront.Alert, error) {
	a := &wavefront.Alert{
		Name: "test alert",
		Target: "[email protected]",
		Condition: "ts(proc.stat.cpu, dc=local) > 100",
		DisplayExpression: "ts(proc.stat.cpu, dc=local)",
		Minutes: 2,
		Tags: []string{"test", "go-wavefront"},
		Severity: "INFO",
	}

	err := alertClient.Create(a)
	if err != nil {
		return nil, err
	}

	return a, nil
}

func get(alertClient *wavefront.Alerts, id string) (*wavefront.Alert, error) {
	a := &wavefront.Alert{
		ID: &id,
	}

	err := alertClient.Get(a)
	if err != nil {
		return nil, err
	}

	return a, nil
}

func update(alertClient *wavefront.Alerts, alert *wavefront.Alert) error {
	err := alertClient.Update(alert)
	if err != nil {
		return err
	}

	return nil
}

func main() {
	config := &wavefront.Config{
		Address: "test.wavefront.com",
		Token: "xxx-xxx-xxx-xxx",
	}

	client, err := wavefront.NewClient(config)
	if err != nil {
		panic(err)
	}

	alerts := client.Alerts()

	// Begin by creating a new alert with 2 tags
	a, err := create(alerts)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Created alert with id %s\n", *a.ID)

	if len(a.Tags) != 2 {
		panic(
			fmt.Sprintf("Expected 2 tags but found %d. Tags: %v.\n",
				len(a.Tags), a.Tags))
	}

	// Append a tag
	a.Tags = append(a.Tags, "appended-tag")

	err = update(alerts, a)
	if err != nil {
		panic(err)
	}

	fmt.Println("Updated alert")

	// Sleep for a little bit so WF can index the new alert
	// If we try to fetch too soon after creating, we can
	// get a 404
	fmt.Println("Waiting for 30s now...")
	time.Sleep(30 * time.Second)

	// fetch the alert again and check tags
	finalAlert, err := get(alerts, *a.ID)
	if err != nil {
		panic(err)
	}

	if len(finalAlert.Tags) != 3 {
		panic(
			fmt.Sprintf("Expected 3 tags but found %d. Tags: %v.\n",
				len(finalAlert.Tags), finalAlert.Tags))
	}

	fmt.Printf("Found tags: %v\n", finalAlert.Tags)
}

Output

$ ./test-update-tags          
Created alert with id 1543955757847
Updated alert
Waiting for 30s now...
Found tags: [appended-tag go-wavefront test]

from go-wavefront.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.