当前位置: 首页>>代码示例>>Golang>>正文


Golang setting.NewConfigContext函数代码示例

本文整理汇总了Golang中github.com/grafana/grafana/pkg/setting.NewConfigContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConfigContext函数的具体用法?Golang NewConfigContext怎么用?Golang NewConfigContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewConfigContext函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestImageUploaderFactory

func TestImageUploaderFactory(t *testing.T) {
	Convey("Can create image uploader for ", t, func() {
		Convey("S3ImageUploader", func() {
			var err error
			setting.NewConfigContext(&setting.CommandLineArgs{
				HomePath: "../../../",
			})

			setting.ImageUploadProvider = "s3"

			s3sec, err := setting.Cfg.GetSection("external_image_storage.s3")
			s3sec.NewKey("bucket_url", "https://foo.bar.baz.s3-us-east-2.amazonaws.com")
			s3sec.NewKey("access_key", "access_key")
			s3sec.NewKey("secret_key", "secret_key")

			uploader, err := NewImageUploader()

			So(err, ShouldBeNil)
			original, ok := uploader.(*S3Uploader)

			So(ok, ShouldBeTrue)
			So(original.region, ShouldEqual, "us-east-2")
			So(original.bucket, ShouldEqual, "foo.bar.baz")
			So(original.accessKey, ShouldEqual, "access_key")
			So(original.secretKey, ShouldEqual, "secret_key")
		})

		Convey("Webdav uploader", func() {
			var err error

			setting.NewConfigContext(&setting.CommandLineArgs{
				HomePath: "../../../",
			})

			setting.ImageUploadProvider = "webdav"

			webdavSec, err := setting.Cfg.GetSection("external_image_storage.webdav")
			webdavSec.NewKey("url", "webdavUrl")
			webdavSec.NewKey("username", "username")
			webdavSec.NewKey("password", "password")

			uploader, err := NewImageUploader()

			So(err, ShouldBeNil)
			original, ok := uploader.(*WebdavUploader)

			So(ok, ShouldBeTrue)
			So(original.url, ShouldEqual, "webdavUrl")
			So(original.username, ShouldEqual, "username")
			So(original.password, ShouldEqual, "password")
		})
	})
}
开发者ID:yuvaraj951,项目名称:grafana,代码行数:53,代码来源:imguploader_test.go

示例2: initRuntime

func initRuntime() {
	setting.NewConfigContext(&setting.CommandLineArgs{
		Config:   *configFile,
		HomePath: *homePath,
		Args:     flag.Args(),
	})

	log.Info("Starting Grafana")
	log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
	setting.LogConfigurationInfo()

	sqlstore.NewEngine()
	sqlstore.EnsureAdminUser()
}
开发者ID:reduxdj,项目名称:grafana,代码行数:14,代码来源:main.go

示例3: TestUploadToS3

func TestUploadToS3(t *testing.T) {
	SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
		setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../../",
		})

		s3Uploader, _ := NewImageUploader()

		path, err := s3Uploader.Upload("../../../public/img/logo_transparent_400x.png")

		So(err, ShouldBeNil)
		So(path, ShouldNotEqual, "")
	})
}
开发者ID:roman-vynar,项目名称:grafana,代码行数:14,代码来源:s3uploader_test.go

示例4: initRuntime

func initRuntime() {
	err := setting.NewConfigContext(&setting.CommandLineArgs{
		Config:   *configFile,
		HomePath: *homePath,
		Args:     flag.Args(),
	})

	if err != nil {
		log.Fatal(3, err.Error())
	}

	logger := log.New("main")
	logger.Info("Starting Grafana", "version", version, "commit", commit, "compiled", time.Unix(setting.BuildStamp, 0))

	setting.LogConfigurationInfo()
}
开发者ID:mdehus,项目名称:grafana,代码行数:16,代码来源:main.go

示例5: TestInterval

func TestInterval(t *testing.T) {
	Convey("Default interval ", t, func() {
		setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../",
		})

		Convey("for 5min", func() {
			tr := NewTimeRange("5m", "now")

			interval := CalculateInterval(tr)
			So(interval.Text, ShouldEqual, "200ms")
		})

		Convey("for 15min", func() {
			tr := NewTimeRange("15m", "now")

			interval := CalculateInterval(tr)
			So(interval.Text, ShouldEqual, "500ms")
		})

		Convey("for 30min", func() {
			tr := NewTimeRange("30m", "now")

			interval := CalculateInterval(tr)
			So(interval.Text, ShouldEqual, "1s")
		})

		Convey("for 1h", func() {
			tr := NewTimeRange("1h", "now")

			interval := CalculateInterval(tr)
			So(interval.Text, ShouldEqual, "2s")
		})

		Convey("Round interval", func() {
			So(roundInterval(time.Millisecond*30), ShouldEqual, time.Millisecond*20)
			So(roundInterval(time.Millisecond*45), ShouldEqual, time.Millisecond*50)
		})

		Convey("Format value", func() {
			So(formatDuration(time.Second*61), ShouldEqual, "1m")
			So(formatDuration(time.Millisecond*30), ShouldEqual, "30ms")
			So(formatDuration(time.Hour*23), ShouldEqual, "23h")
			So(formatDuration(time.Hour*24*367), ShouldEqual, "1y")
		})
	})
}
开发者ID:yuvaraj951,项目名称:grafana,代码行数:47,代码来源:interval_test.go

示例6: initRuntime

func initRuntime() {
	exportDatabaseServiceEnv()

	err := setting.NewConfigContext(&setting.CommandLineArgs{
		Config:   *configFile,
		HomePath: *homePath,
		Args:     flag.Args(),
	})

	if err != nil {
		log.Fatal(3, err.Error())
	}

	log.Info("Starting Grafana")
	log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
	setting.LogConfigurationInfo()

	sqlstore.NewEngine()
	sqlstore.EnsureAdminUser()
}
开发者ID:gaos1,项目名称:grafana,代码行数:20,代码来源:main.go

示例7: runDbCommand

func runDbCommand(command func(commandLine CommandLine) error) func(context *cli.Context) {
	return func(context *cli.Context) {

		flag.Parse()
		setting.NewConfigContext(&setting.CommandLineArgs{
			Config:   *configFile,
			HomePath: *homePath,
			Args:     flag.Args(),
		})

		sqlstore.NewEngine()

		cmd := &contextCommandLine{context}
		if err := command(cmd); err != nil {
			logger.Errorf("\n%s: ", color.RedString("Error"))
			logger.Errorf("%s\n\n", err)

			cmd.ShowHelp()
			os.Exit(1)
		} else {
			logger.Info("\n\n")
		}
	}
}
开发者ID:mapr,项目名称:grafana,代码行数:24,代码来源:commands.go

示例8: TestAlertRuleExtraction

func TestAlertRuleExtraction(t *testing.T) {

	Convey("Parsing alert rules  from dashboard json", t, func() {

		RegisterCondition("query", func(model *simplejson.Json, index int) (Condition, error) {
			return &FakeCondition{}, nil
		})

		setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../../",
		})

		// mock data
		defaultDs := &m.DataSource{Id: 12, OrgId: 1, Name: "I am default", IsDefault: true}
		graphite2Ds := &m.DataSource{Id: 15, OrgId: 1, Name: "graphite2"}
		influxDBDs := &m.DataSource{Id: 16, OrgId: 1, Name: "InfluxDB"}

		bus.AddHandler("test", func(query *m.GetDataSourcesQuery) error {
			query.Result = []*m.DataSource{defaultDs, graphite2Ds}
			return nil
		})

		bus.AddHandler("test", func(query *m.GetDataSourceByNameQuery) error {
			if query.Name == defaultDs.Name {
				query.Result = defaultDs
			}
			if query.Name == graphite2Ds.Name {
				query.Result = graphite2Ds
			}
			if query.Name == influxDBDs.Name {
				query.Result = influxDBDs
			}
			return nil
		})

		json := `
      {
        "id": 57,
        "title": "Graphite 4",
        "originalTitle": "Graphite 4",
        "tags": ["graphite"],
        "rows": [
        {
          "panels": [
          {
            "title": "Active desktop users",
            "editable": true,
            "type": "graph",
            "id": 3,
            "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(statsd.fakesite.counters.session_start.desktop.count, 4)"
            }
            ],
            "datasource": null,
            "alert": {
              "name": "name1",
              "message": "desc1",
              "handler": 1,
              "frequency": "60s",
              "conditions": [
              {
                "type": "query",
                "query": {"params": ["A", "5m", "now"]},
                "reducer": {"type": "avg", "params": []},
                "evaluator": {"type": ">", "params": [100]}
              }
              ]
            }
          },
          {
            "title": "Active mobile users",
            "id": 4,
            "targets": [
              {"refId": "A", "target": ""},
              {"refId": "B", "target": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)"}
            ],
            "datasource": "graphite2",
            "alert": {
              "name": "name2",
              "message": "desc2",
              "handler": 0,
              "frequency": "60s",
              "severity": "warning",
              "conditions": [
              {
                "type": "query",
                "query":  {"params": ["B", "5m", "now"]},
                "reducer": {"type": "avg", "params": []},
                "evaluator": {"type": ">", "params": [100]}
              }
              ]
            }
          }
          ]
        }
      ]
      }`

//.........这里部分代码省略.........
开发者ID:wk66,项目名称:grafana,代码行数:101,代码来源:extractor_test.go

示例9: TestInfluxdbResponseParser

func TestInfluxdbResponseParser(t *testing.T) {
	Convey("Influxdb response parser", t, func() {
		Convey("Response parser", func() {
			parser := &ResponseParser{}

			setting.NewConfigContext(&setting.CommandLineArgs{
				HomePath: "../../../",
			})

			response := &Response{
				Results: []Result{
					Result{
						Series: []Row{
							{
								Name:    "cpu",
								Columns: []string{"time", "mean", "sum"},
								Tags:    map[string]string{"datacenter": "America"},
								Values: [][]interface{}{
									{json.Number("111"), json.Number("222"), json.Number("333")},
									{json.Number("111"), json.Number("222"), json.Number("333")},
									{json.Number("111"), json.Number("null"), json.Number("333")},
								},
							},
						},
					},
				},
			}

			query := &Query{}

			result := parser.Parse(response, query)

			Convey("can parse all series", func() {
				So(len(result.Series), ShouldEqual, 2)
			})

			Convey("can parse all points", func() {
				So(len(result.Series[0].Points), ShouldEqual, 3)
				So(len(result.Series[1].Points), ShouldEqual, 3)
			})

			Convey("can parse multi row result", func() {
				So(result.Series[0].Points[1][0].Float64, ShouldEqual, float64(222))
				So(result.Series[1].Points[1][0].Float64, ShouldEqual, float64(333))
			})

			Convey("can parse null points", func() {
				So(result.Series[0].Points[2][0].Valid, ShouldBeFalse)
			})

			Convey("can format serie names", func() {
				So(result.Series[0].Name, ShouldEqual, "cpu.mean { datacenter: America }")
				So(result.Series[1].Name, ShouldEqual, "cpu.sum { datacenter: America }")
			})
		})

		Convey("Response parser with alias", func() {
			parser := &ResponseParser{}

			response := &Response{
				Results: []Result{
					Result{
						Series: []Row{
							{
								Name:    "cpu.upc",
								Columns: []string{"time", "mean", "sum"},
								Tags:    map[string]string{"datacenter": "America"},
								Values: [][]interface{}{
									{json.Number("111"), json.Number("222"), json.Number("333")},
								},
							},
						},
					},
				},
			}

			Convey("$ alias", func() {
				Convey("simple alias", func() {
					query := &Query{Alias: "serie alias"}
					result := parser.Parse(response, query)

					So(result.Series[0].Name, ShouldEqual, "serie alias")
				})

				Convey("measurement alias", func() {
					query := &Query{Alias: "alias $m $measurement", Measurement: "10m"}
					result := parser.Parse(response, query)

					So(result.Series[0].Name, ShouldEqual, "alias 10m 10m")
				})

				Convey("column alias", func() {
					query := &Query{Alias: "alias $col", Measurement: "10m"}
					result := parser.Parse(response, query)

					So(result.Series[0].Name, ShouldEqual, "alias mean")
					So(result.Series[1].Name, ShouldEqual, "alias sum")
				})

				Convey("tag alias", func() {
//.........这里部分代码省略.........
开发者ID:utkarshcmu,项目名称:grafana,代码行数:101,代码来源:response_parser_test.go

示例10: TestGraphitePublisher

func TestGraphitePublisher(t *testing.T) {

	setting.CustomInitPath = "conf/does_not_exist.ini"

	Convey("Test graphite prefix replacement", t, func() {
		var err error
		err = setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../",
		})

		So(err, ShouldBeNil)

		sec, err := setting.Cfg.NewSection("metrics.graphite")
		sec.NewKey("prefix", "prod.grafana.%(instance_name)s.")
		sec.NewKey("address", "localhost:2001")

		So(err, ShouldBeNil)

		setting.InstanceName = "hostname.with.dots.com"
		publisher, err := CreateGraphitePublisher()

		So(err, ShouldBeNil)
		So(publisher, ShouldNotBeNil)

		So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
		So(publisher.address, ShouldEqual, "localhost:2001")
	})

	Convey("Test graphite publisher default prefix", t, func() {
		var err error
		err = setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../",
		})

		So(err, ShouldBeNil)

		sec, err := setting.Cfg.NewSection("metrics.graphite")
		sec.NewKey("address", "localhost:2001")

		So(err, ShouldBeNil)

		setting.InstanceName = "hostname.with.dots.com"
		publisher, err := CreateGraphitePublisher()

		So(err, ShouldBeNil)
		So(publisher, ShouldNotBeNil)

		So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
		So(publisher.address, ShouldEqual, "localhost:2001")
	})

	Convey("Test graphite publisher default values", t, func() {
		var err error
		err = setting.NewConfigContext(&setting.CommandLineArgs{
			HomePath: "../../",
		})

		So(err, ShouldBeNil)

		_, err = setting.Cfg.NewSection("metrics.graphite")

		publisher, err := CreateGraphitePublisher()

		So(err, ShouldBeNil)
		So(publisher, ShouldBeNil)
	})
}
开发者ID:roman-vynar,项目名称:grafana,代码行数:67,代码来源:graphite_test.go


注:本文中的github.com/grafana/grafana/pkg/setting.NewConfigContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。