This commit is contained in:
Mariana Cardoso 2018-04-12 14:34:35 -07:00 коммит произвёл Troy Dai
Родитель bca0242a17
Коммит 20af695890
9 изменённых файлов: 95 добавлений и 183 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -18,3 +18,6 @@ bin/
.idea/
vendor/
secret
secrets

Просмотреть файл

@ -6,7 +6,7 @@ before_install:
- sudo apt-get install -y apt-transport-https
- sudo apt-get -qq update && sudo apt-get install -y azure-cli
go:
- '1.9'
- '1.10.x'
script:
- go get -u github.com/golang/dep/cmd/dep
- dep ensure

207
Gopkg.lock сгенерированный
Просмотреть файл

@ -9,10 +9,7 @@
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"proto",
"sortkeys"
]
packages = ["proto","sortkeys"]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
@ -24,13 +21,7 @@
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/timestamp"
]
packages = ["proto","ptypes","ptypes/any","ptypes/duration","ptypes/timestamp"]
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
version = "v1.0.0"
@ -48,21 +39,14 @@
[[projects]]
name = "github.com/googleapis/gnostic"
packages = [
"OpenAPIv2",
"compiler",
"extensions"
]
packages = ["OpenAPIv2","compiler","extensions"]
revision = "ee43cbb60db7bd22502942cccbc39059117352ab"
version = "v0.1.0"
[[projects]]
branch = "master"
name = "github.com/gregjones/httpcache"
packages = [
".",
"diskcache"
]
packages = [".","diskcache"]
revision = "9cad4c3443a7200dd6400aef47183728de563a38"
[[projects]]
@ -74,14 +58,14 @@
[[projects]]
name = "github.com/imdario/mergo"
packages = ["."]
revision = "163f41321a19dd09362d4c63cc2489db2015f1f4"
version = "0.3.2"
revision = "9d5f1277e9a8ed20c3684bda8fde67c05628518c"
version = "v0.3.4"
[[projects]]
name = "github.com/json-iterator/go"
packages = ["."]
revision = "3353055b2a1a5ae1b6a8dfde887a524e7088f3a2"
version = "1.1.2"
revision = "ca39e5af3ece67bbcda3d0f4f56a8e24d9f2dad4"
version = "1.1.3"
[[projects]]
name = "github.com/juju/ratelimit"
@ -92,8 +76,8 @@
[[projects]]
name = "github.com/modern-go/concurrent"
packages = ["."]
revision = "938152ca6a933f501bb238954eebd3cbcbf489ff"
version = "1.0.2"
revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94"
version = "1.0.3"
[[projects]]
name = "github.com/modern-go/reflect2"
@ -116,201 +100,66 @@
[[projects]]
name = "github.com/spf13/pflag"
packages = ["."]
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
version = "v1.0.0"
revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
version = "v1.0.1"
[[projects]]
branch = "master"
name = "github.com/streadway/amqp"
packages = ["."]
revision = "d27ae102b8892a98ca4edb74539436af62577379"
revision = "8e4aba63da9fc5571e01c6a45dc809a58cbc5a68"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = ["ssh/terminal"]
revision = "91a49db82a88618983a78a06c1cbd4e00ab749ab"
revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"http2",
"http2/hpack",
"idna",
"lex/httplex"
]
revision = "22ae77b79946ea320088417e4d50825671d82d57"
packages = ["http2","http2/hpack","idna","lex/httplex"]
revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = [
"unix",
"windows"
]
revision = "dd2ff4accc098aceecb86b36eaa7829b2a17b1c9"
packages = ["unix","windows"]
revision = "3b87a42e500a6dc65dae1a55d0b641295971163e"
[[projects]]
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
]
packages = ["collate","collate/build","internal/colltab","internal/gen","internal/tag","internal/triegen","internal/ucd","language","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable"]
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
name = "gopkg.in/inf.v0"
packages = ["."]
revision = "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4"
version = "v0.9.0"
revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf"
version = "v0.9.1"
[[projects]]
name = "gopkg.in/yaml.v2"
packages = ["."]
revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5"
version = "v2.1.1"
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
version = "v2.2.1"
[[projects]]
branch = "master"
name = "k8s.io/api"
packages = [
"admissionregistration/v1alpha1",
"admissionregistration/v1beta1",
"apps/v1",
"apps/v1beta1",
"apps/v1beta2",
"authentication/v1",
"authentication/v1beta1",
"authorization/v1",
"authorization/v1beta1",
"autoscaling/v1",
"autoscaling/v2beta1",
"batch/v1",
"batch/v1beta1",
"batch/v2alpha1",
"certificates/v1beta1",
"core/v1",
"events/v1beta1",
"extensions/v1beta1",
"networking/v1",
"policy/v1beta1",
"rbac/v1",
"rbac/v1alpha1",
"rbac/v1beta1",
"scheduling/v1alpha1",
"settings/v1alpha1",
"storage/v1",
"storage/v1alpha1",
"storage/v1beta1"
]
revision = "7ebfdc5e7dfac82cc5c53e1259ad579915950e20"
packages = ["admissionregistration/v1alpha1","admissionregistration/v1beta1","apps/v1","apps/v1beta1","apps/v1beta2","authentication/v1","authentication/v1beta1","authorization/v1","authorization/v1beta1","autoscaling/v1","autoscaling/v2beta1","batch/v1","batch/v1beta1","batch/v2alpha1","certificates/v1beta1","core/v1","events/v1beta1","extensions/v1beta1","networking/v1","policy/v1beta1","rbac/v1","rbac/v1alpha1","rbac/v1beta1","scheduling/v1alpha1","settings/v1alpha1","storage/v1","storage/v1alpha1","storage/v1beta1"]
revision = "847e24b2c0e587a6a097d187ebd72e1ca24de001"
[[projects]]
branch = "master"
name = "k8s.io/apimachinery"
packages = [
"pkg/api/errors",
"pkg/api/meta",
"pkg/api/resource",
"pkg/apis/meta/v1",
"pkg/apis/meta/v1/unstructured",
"pkg/apis/meta/v1beta1",
"pkg/conversion",
"pkg/conversion/queryparams",
"pkg/fields",
"pkg/labels",
"pkg/runtime",
"pkg/runtime/schema",
"pkg/runtime/serializer",
"pkg/runtime/serializer/json",
"pkg/runtime/serializer/protobuf",
"pkg/runtime/serializer/recognizer",
"pkg/runtime/serializer/streaming",
"pkg/runtime/serializer/versioning",
"pkg/selection",
"pkg/types",
"pkg/util/clock",
"pkg/util/errors",
"pkg/util/framer",
"pkg/util/intstr",
"pkg/util/json",
"pkg/util/net",
"pkg/util/runtime",
"pkg/util/sets",
"pkg/util/validation",
"pkg/util/validation/field",
"pkg/util/wait",
"pkg/util/yaml",
"pkg/version",
"pkg/watch",
"third_party/forked/golang/reflect"
]
revision = "e9ff529c66f83aeac6dff90f11ea0c5b7c4d626a"
packages = ["pkg/api/errors","pkg/api/meta","pkg/api/resource","pkg/apis/meta/v1","pkg/apis/meta/v1/unstructured","pkg/apis/meta/v1beta1","pkg/conversion","pkg/conversion/queryparams","pkg/fields","pkg/labels","pkg/runtime","pkg/runtime/schema","pkg/runtime/serializer","pkg/runtime/serializer/json","pkg/runtime/serializer/protobuf","pkg/runtime/serializer/recognizer","pkg/runtime/serializer/streaming","pkg/runtime/serializer/versioning","pkg/selection","pkg/types","pkg/util/clock","pkg/util/errors","pkg/util/framer","pkg/util/intstr","pkg/util/json","pkg/util/net","pkg/util/runtime","pkg/util/sets","pkg/util/validation","pkg/util/validation/field","pkg/util/wait","pkg/util/yaml","pkg/version","pkg/watch","third_party/forked/golang/reflect"]
revision = "895b82eadff27f5a6b19d80628a04645823c1e46"
[[projects]]
name = "k8s.io/client-go"
packages = [
"discovery",
"kubernetes",
"kubernetes/scheme",
"kubernetes/typed/admissionregistration/v1alpha1",
"kubernetes/typed/admissionregistration/v1beta1",
"kubernetes/typed/apps/v1",
"kubernetes/typed/apps/v1beta1",
"kubernetes/typed/apps/v1beta2",
"kubernetes/typed/authentication/v1",
"kubernetes/typed/authentication/v1beta1",
"kubernetes/typed/authorization/v1",
"kubernetes/typed/authorization/v1beta1",
"kubernetes/typed/autoscaling/v1",
"kubernetes/typed/autoscaling/v2beta1",
"kubernetes/typed/batch/v1",
"kubernetes/typed/batch/v1beta1",
"kubernetes/typed/batch/v2alpha1",
"kubernetes/typed/certificates/v1beta1",
"kubernetes/typed/core/v1",
"kubernetes/typed/events/v1beta1",
"kubernetes/typed/extensions/v1beta1",
"kubernetes/typed/networking/v1",
"kubernetes/typed/policy/v1beta1",
"kubernetes/typed/rbac/v1",
"kubernetes/typed/rbac/v1alpha1",
"kubernetes/typed/rbac/v1beta1",
"kubernetes/typed/scheduling/v1alpha1",
"kubernetes/typed/settings/v1alpha1",
"kubernetes/typed/storage/v1",
"kubernetes/typed/storage/v1alpha1",
"kubernetes/typed/storage/v1beta1",
"pkg/version",
"rest",
"rest/watch",
"tools/auth",
"tools/clientcmd",
"tools/clientcmd/api",
"tools/clientcmd/api/latest",
"tools/clientcmd/api/v1",
"tools/metrics",
"tools/reference",
"transport",
"util/cert",
"util/flowcontrol",
"util/homedir",
"util/integer"
]
packages = ["discovery","kubernetes","kubernetes/scheme","kubernetes/typed/admissionregistration/v1alpha1","kubernetes/typed/admissionregistration/v1beta1","kubernetes/typed/apps/v1","kubernetes/typed/apps/v1beta1","kubernetes/typed/apps/v1beta2","kubernetes/typed/authentication/v1","kubernetes/typed/authentication/v1beta1","kubernetes/typed/authorization/v1","kubernetes/typed/authorization/v1beta1","kubernetes/typed/autoscaling/v1","kubernetes/typed/autoscaling/v2beta1","kubernetes/typed/batch/v1","kubernetes/typed/batch/v1beta1","kubernetes/typed/batch/v2alpha1","kubernetes/typed/certificates/v1beta1","kubernetes/typed/core/v1","kubernetes/typed/events/v1beta1","kubernetes/typed/extensions/v1beta1","kubernetes/typed/networking/v1","kubernetes/typed/policy/v1beta1","kubernetes/typed/rbac/v1","kubernetes/typed/rbac/v1alpha1","kubernetes/typed/rbac/v1beta1","kubernetes/typed/scheduling/v1alpha1","kubernetes/typed/settings/v1alpha1","kubernetes/typed/storage/v1","kubernetes/typed/storage/v1alpha1","kubernetes/typed/storage/v1beta1","pkg/version","rest","rest/watch","tools/auth","tools/clientcmd","tools/clientcmd/api","tools/clientcmd/api/latest","tools/clientcmd/api/v1","tools/metrics","tools/reference","transport","util/cert","util/flowcontrol","util/homedir","util/integer"]
revision = "78700dec6369ba22221b72770783300f143df150"
version = "v6.0.0"

Просмотреть файл

@ -20,7 +20,6 @@
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.1.1"

Просмотреть файл

@ -10,6 +10,7 @@ const (
StorageVolumeNameTools = "tools-storage"
DNSNameTaskStore = "store-internal-svc"
DNSNameEmailService = "email-internal-svc"
DNSNameReportService = "report-internal-svc"
SecretNameAgents = "agent-secrets"
SystemConfigmapName = "a01-system-config"
)

Просмотреть файл

@ -104,6 +104,8 @@ func main() {
common.ExitOnError(err, "Failed to get the kubernetes secret")
}
reportutils.RefreshPowerBI(run, run.GetSecretName(droidMetadata))
owners := string(secret.Data["owners"])
templateURL, ok := secret.Data["email.path.template"]
if ok {

Просмотреть файл

@ -6,6 +6,7 @@ import (
"net/http"
"os/exec"
"regexp"
"strings"
"github.com/Azure/adx-automation-agent/common"
"github.com/Azure/adx-automation-agent/httputils"
@ -124,3 +125,9 @@ func QueryRun(runID int) (*Run, error) {
return &run, nil
}
// IsOfficial returns true if the run is an official run
func (run *Run) IsOfficial() bool {
remark, ok := run.Settings[common.KeyRemark]
return ok && strings.ToLower(remark.(string)) == "official"
}

52
reportutils/powerbi.go Normal file
Просмотреть файл

@ -0,0 +1,52 @@
package reportutils
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/Azure/adx-automation-agent/common"
"github.com/Azure/adx-automation-agent/models"
)
// RefreshPowerBI requests the PowerBI service to refresh a dataset
func RefreshPowerBI(run *models.Run, product string) {
if !run.IsOfficial() {
common.LogInfo("Skip PowerBI refresh: run is not official")
return
}
common.LogInfo("sending PowerBI refresh request...")
content := map[string]interface{}{
"product": product,
"runID": run.ID,
}
body, err := json.Marshal(content)
if err != nil {
common.LogInfo("Fail to marshal JSON during request refreshing PowerBI.")
return
}
req, err := http.NewRequest(
http.MethodPost,
fmt.Sprintf("http://%s/report", common.DNSNameReportService),
bytes.NewBuffer(body))
if err != nil {
common.LogInfo(fmt.Sprintf("Fail to create request to refresh PowerBI: %v", err))
return
}
req.Header.Set("Content-Type", "application/json")
resp, err := httpClient.Do(req)
if err != nil {
common.LogInfo(fmt.Sprintf("Fail to send request to PowerBI service: %v", err))
return
}
if resp.StatusCode != http.StatusOK {
common.LogInfo(fmt.Sprintf("The request may have failed. Status code: %d", resp.StatusCode))
return
}
common.LogInfo("Finished sending PowerBI refresh request")
}

Просмотреть файл

@ -20,8 +20,7 @@ func Report(run *models.Run, receivers []string, templateURL string) {
// Emails should not be sent to all the team if the run was not set with a remark
// Only acceptable remark for sending emails to whole team is 'official'
remark, ok := run.Settings[common.KeyRemark]
if !ok || (ok && strings.ToLower(remark.(string)) != "official") {
if !run.IsOfficial() {
receivers = []string{}
}