Skip to content

Commit 9fc91b7

Browse files
committed
fixed gofmt issue
1 parent 04eefb8 commit 9fc91b7

File tree

3 files changed

+75
-73
lines changed

3 files changed

+75
-73
lines changed

pkg/api/cloudwatch/metrics.go

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,56 @@ var dimensionsMap map[string][]string
1212

1313
func init() {
1414
metricsMap = map[string][]string{
15-
"AWS/AutoScaling": []string{"GroupMinSize", "GroupMaxSize", "GroupDesiredCapacity", "GroupInServiceInstances", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances"},
16-
"AWS/Billing": []string{"EstimatedCharges"},
17-
"AWS/EC2": []string{"CPUCreditUsage", "CPUCreditBalance", "CPUUtilization", "DiskReadOps", "DiskWriteOps", "DiskReadBytes", "DiskWriteBytes", "NetworkIn", "NetworkOut", "StatusCheckFailed", "StatusCheckFailed_Instance", "StatusCheckFailed_System"},
18-
"AWS/CloudFront": []string{"Requests", "BytesDownloaded", "BytesUploaded", "TotalErrorRate", "4xxErrorRate", "5xxErrorRate"},
19-
"AWS/CloudSearch": []string{"SuccessfulRequests", "SearchableDocuments", "IndexUtilization", "Partitions"},
20-
"AWS/DynamoDB": []string{"ConditionalCheckFailedRequests", "ConsumedReadCapacityUnits", "ConsumedWriteCapacityUnits", "OnlineIndexConsumedWriteCapacity", "OnlineIndexPercentageProgress", "OnlineIndexThrottleEvents", "ProvisionedReadCapacityUnits", "ProvisionedWriteCapacityUnits", "ReadThrottleEvents", "ReturnedItemCount", "SuccessfulRequestLatency", "SystemErrors", "ThrottledRequests", "UserErrors", "WriteThrottleEvents"},
21-
"AWS/ElastiCache": []string{
15+
"AWS/AutoScaling": {"GroupMinSize", "GroupMaxSize", "GroupDesiredCapacity", "GroupInServiceInstances", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances"},
16+
"AWS/Billing": {"EstimatedCharges"},
17+
"AWS/EC2": {"CPUCreditUsage", "CPUCreditBalance", "CPUUtilization", "DiskReadOps", "DiskWriteOps", "DiskReadBytes", "DiskWriteBytes", "NetworkIn", "NetworkOut", "StatusCheckFailed", "StatusCheckFailed_Instance", "StatusCheckFailed_System"},
18+
"AWS/CloudFront": {"Requests", "BytesDownloaded", "BytesUploaded", "TotalErrorRate", "4xxErrorRate", "5xxErrorRate"},
19+
"AWS/CloudSearch": {"SuccessfulRequests", "SearchableDocuments", "IndexUtilization", "Partitions"},
20+
"AWS/DynamoDB": {"ConditionalCheckFailedRequests", "ConsumedReadCapacityUnits", "ConsumedWriteCapacityUnits", "OnlineIndexConsumedWriteCapacity", "OnlineIndexPercentageProgress", "OnlineIndexThrottleEvents", "ProvisionedReadCapacityUnits", "ProvisionedWriteCapacityUnits", "ReadThrottleEvents", "ReturnedItemCount", "SuccessfulRequestLatency", "SystemErrors", "ThrottledRequests", "UserErrors", "WriteThrottleEvents"},
21+
"AWS/ElastiCache": {
2222
"CPUUtilization", "SwapUsage", "FreeableMemory", "NetworkBytesIn", "NetworkBytesOut",
2323
"BytesUsedForCacheItems", "BytesReadIntoMemcached", "BytesWrittenOutFromMemcached", "CasBadval", "CasHits", "CasMisses", "CmdFlush", "CmdGet", "CmdSet", "CurrConnections", "CurrItems", "DecrHits", "DecrMisses", "DeleteHits", "DeleteMisses", "Evictions", "GetHits", "GetMisses", "IncrHits", "IncrMisses", "Reclaimed",
2424
"CurrConnections", "Evictions", "Reclaimed", "NewConnections", "BytesUsedForCache", "CacheHits", "CacheMisses", "ReplicationLag", "GetTypeCmds", "SetTypeCmds", "KeyBasedCmds", "StringBasedCmds", "HashBasedCmds", "ListBasedCmds", "SetBasedCmds", "SortedSetBasedCmds", "CurrItems",
2525
},
26-
"AWS/EBS": []string{"VolumeReadBytes", "VolumeWriteBytes", "VolumeReadOps", "VolumeWriteOps", "VolumeTotalReadTime", "VolumeTotalWriteTime", "VolumeIdleTime", "VolumeQueueLength", "VolumeThroughputPercentage", "VolumeConsumedReadWriteOps"},
27-
"AWS/ELB": []string{"HealthyHostCount", "UnHealthyHostCount", "RequestCount", "Latency", "HTTPCode_ELB_4XX", "HTTPCode_ELB_5XX", "HTTPCode_Backend_2XX", "HTTPCode_Backend_3XX", "HTTPCode_Backend_4XX", "HTTPCode_Backend_5XX", "BackendConnectionErrors", "SurgeQueueLength", "SpilloverCount"},
28-
"AWS/ElasticMapReduce": []string{"CoreNodesPending", "CoreNodesRunning", "HBaseBackupFailed", "HBaseMostRecentBackupDuration", "HBaseTimeSinceLastSuccessfulBackup", "HDFSBytesRead", "HDFSBytesWritten", "HDFSUtilization", "IsIdle", "JobsFailed", "JobsRunning", "LiveDataNodes", "LiveTaskTrackers", "MapSlotsOpen", "MissingBlocks", "ReduceSlotsOpen", "RemainingMapTasks", "RemainingMapTasksPerSlot", "RemainingReduceTasks", "RunningMapTasks", "RunningReduceTasks", "S3BytesRead", "S3BytesWritten", "TaskNodesPending", "TaskNodesRunning", "TotalLoad"},
29-
"AWS/Kinesis": []string{"PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Success", "PutRecords.Bytes", "PutRecords.Latency", "PutRecords.Records", "PutRecords.Success", "IncomingBytes", "IncomingRecords", "GetRecords.Bytes", "GetRecords.IteratorAgeMilliseconds", "GetRecords.Latency", "GetRecords.Success"},
30-
"AWS/ML": []string{"PredictCount", "PredictFailureCount"},
31-
"AWS/OpsWorks": []string{"cpu_idle", "cpu_nice", "cpu_system", "cpu_user", "cpu_waitio", "load_1", "load_5", "load_15", "memory_buffers", "memory_cached", "memory_free", "memory_swap", "memory_total", "memory_used", "procs"},
32-
"AWS/Redshift": []string{"CPUUtilization", "DatabaseConnections", "HealthStatus", "MaintenanceMode", "NetworkReceiveThroughput", "NetworkTransmitThroughput", "PercentageDiskSpaceUsed", "ReadIOPS", "ReadLatency", "ReadThroughput", "WriteIOPS", "WriteLatency", "WriteThroughput"},
33-
"AWS/RDS": []string{"BinLogDiskUsage", "CPUUtilization", "DatabaseConnections", "DiskQueueDepth", "FreeableMemory", "FreeStorageSpace", "ReplicaLag", "SwapUsage", "ReadIOPS", "WriteIOPS", "ReadLatency", "WriteLatency", "ReadThroughput", "WriteThroughput", "NetworkReceiveThroughput", "NetworkTransmitThroughput"},
34-
"AWS/Route53": []string{"HealthCheckStatus", "HealthCheckPercentageHealthy"},
35-
"AWS/SNS": []string{"NumberOfMessagesPublished", "PublishSize", "NumberOfNotificationsDelivered", "NumberOfNotificationsFailed"},
36-
"AWS/SQS": []string{"NumberOfMessagesSent", "SentMessageSize", "NumberOfMessagesReceived", "NumberOfEmptyReceives", "NumberOfMessagesDeleted", "ApproximateNumberOfMessagesDelayed", "ApproximateNumberOfMessagesVisible", "ApproximateNumberOfMessagesNotVisible"},
37-
"AWS/S3": []string{"BucketSizeBytes", "NumberOfObjects"},
38-
"AWS/SWF": []string{"DecisionTaskScheduleToStartTime", "DecisionTaskStartToCloseTime", "DecisionTasksCompleted", "StartedDecisionTasksTimedOutOnClose", "WorkflowStartToCloseTime", "WorkflowsCanceled", "WorkflowsCompleted", "WorkflowsContinuedAsNew", "WorkflowsFailed", "WorkflowsTerminated", "WorkflowsTimedOut"},
39-
"AWS/StorageGateway": []string{"CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "CloudBytesDownloaded", "CloudDownloadLatency", "CloudBytesUploaded", "UploadBufferFree", "UploadBufferPercentUsed", "UploadBufferUsed", "QueuedWrites", "ReadBytes", "ReadTime", "TotalCacheSize", "WriteBytes", "WriteTime", "WorkingStorageFree", "WorkingStoragePercentUsed", "WorkingStorageUsed", "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "ReadBytes", "ReadTime", "WriteBytes", "WriteTime", "QueuedWrites"},
40-
"AWS/WorkSpaces": []string{"Available", "Unhealthy", "ConnectionAttempt", "ConnectionSuccess", "ConnectionFailure", "SessionLaunchTime", "InSessionLatency", "SessionDisconnect"},
26+
"AWS/EBS": {"VolumeReadBytes", "VolumeWriteBytes", "VolumeReadOps", "VolumeWriteOps", "VolumeTotalReadTime", "VolumeTotalWriteTime", "VolumeIdleTime", "VolumeQueueLength", "VolumeThroughputPercentage", "VolumeConsumedReadWriteOps"},
27+
"AWS/ELB": {"HealthyHostCount", "UnHealthyHostCount", "RequestCount", "Latency", "HTTPCode_ELB_4XX", "HTTPCode_ELB_5XX", "HTTPCode_Backend_2XX", "HTTPCode_Backend_3XX", "HTTPCode_Backend_4XX", "HTTPCode_Backend_5XX", "BackendConnectionErrors", "SurgeQueueLength", "SpilloverCount"},
28+
"AWS/ElasticMapReduce": {"CoreNodesPending", "CoreNodesRunning", "HBaseBackupFailed", "HBaseMostRecentBackupDuration", "HBaseTimeSinceLastSuccessfulBackup", "HDFSBytesRead", "HDFSBytesWritten", "HDFSUtilization", "IsIdle", "JobsFailed", "JobsRunning", "LiveDataNodes", "LiveTaskTrackers", "MapSlotsOpen", "MissingBlocks", "ReduceSlotsOpen", "RemainingMapTasks", "RemainingMapTasksPerSlot", "RemainingReduceTasks", "RunningMapTasks", "RunningReduceTasks", "S3BytesRead", "S3BytesWritten", "TaskNodesPending", "TaskNodesRunning", "TotalLoad"},
29+
"AWS/Kinesis": {"PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Success", "PutRecords.Bytes", "PutRecords.Latency", "PutRecords.Records", "PutRecords.Success", "IncomingBytes", "IncomingRecords", "GetRecords.Bytes", "GetRecords.IteratorAgeMilliseconds", "GetRecords.Latency", "GetRecords.Success"},
30+
"AWS/ML": {"PredictCount", "PredictFailureCount"},
31+
"AWS/OpsWorks": {"cpu_idle", "cpu_nice", "cpu_system", "cpu_user", "cpu_waitio", "load_1", "load_5", "load_15", "memory_buffers", "memory_cached", "memory_free", "memory_swap", "memory_total", "memory_used", "procs"},
32+
"AWS/Redshift": {"CPUUtilization", "DatabaseConnections", "HealthStatus", "MaintenanceMode", "NetworkReceiveThroughput", "NetworkTransmitThroughput", "PercentageDiskSpaceUsed", "ReadIOPS", "ReadLatency", "ReadThroughput", "WriteIOPS", "WriteLatency", "WriteThroughput"},
33+
"AWS/RDS": {"BinLogDiskUsage", "CPUUtilization", "DatabaseConnections", "DiskQueueDepth", "FreeableMemory", "FreeStorageSpace", "ReplicaLag", "SwapUsage", "ReadIOPS", "WriteIOPS", "ReadLatency", "WriteLatency", "ReadThroughput", "WriteThroughput", "NetworkReceiveThroughput", "NetworkTransmitThroughput"},
34+
"AWS/Route53": {"HealthCheckStatus", "HealthCheckPercentageHealthy"},
35+
"AWS/SNS": {"NumberOfMessagesPublished", "PublishSize", "NumberOfNotificationsDelivered", "NumberOfNotificationsFailed"},
36+
"AWS/SQS": {"NumberOfMessagesSent", "SentMessageSize", "NumberOfMessagesReceived", "NumberOfEmptyReceives", "NumberOfMessagesDeleted", "ApproximateNumberOfMessagesDelayed", "ApproximateNumberOfMessagesVisible", "ApproximateNumberOfMessagesNotVisible"},
37+
"AWS/S3": {"BucketSizeBytes", "NumberOfObjects"},
38+
"AWS/SWF": {"DecisionTaskScheduleToStartTime", "DecisionTaskStartToCloseTime", "DecisionTasksCompleted", "StartedDecisionTasksTimedOutOnClose", "WorkflowStartToCloseTime", "WorkflowsCanceled", "WorkflowsCompleted", "WorkflowsContinuedAsNew", "WorkflowsFailed", "WorkflowsTerminated", "WorkflowsTimedOut"},
39+
"AWS/StorageGateway": {"CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "CloudBytesDownloaded", "CloudDownloadLatency", "CloudBytesUploaded", "UploadBufferFree", "UploadBufferPercentUsed", "UploadBufferUsed", "QueuedWrites", "ReadBytes", "ReadTime", "TotalCacheSize", "WriteBytes", "WriteTime", "WorkingStorageFree", "WorkingStoragePercentUsed", "WorkingStorageUsed", "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "ReadBytes", "ReadTime", "WriteBytes", "WriteTime", "QueuedWrites"},
40+
"AWS/WorkSpaces": {"Available", "Unhealthy", "ConnectionAttempt", "ConnectionSuccess", "ConnectionFailure", "SessionLaunchTime", "InSessionLatency", "SessionDisconnect"},
4141
}
4242
dimensionsMap = map[string][]string{
43-
"AWS/AutoScaling": []string{"AutoScalingGroupName"},
44-
"AWS/Billing": []string{"ServiceName", "LinkedAccount", "Currency"},
45-
"AWS/CloudFront": []string{"DistributionId", "Region"},
46-
"AWS/CloudSearch": []string{},
47-
"AWS/DynamoDB": []string{"TableName", "GlobalSecondaryIndexName", "Operation"},
48-
"AWS/ElastiCache": []string{"CacheClusterId", "CacheNodeId"},
49-
"AWS/EBS": []string{"VolumeId"},
50-
"AWS/EC2": []string{"AutoScalingGroupName", "ImageId", "InstanceId", "InstanceType"},
51-
"AWS/ELB": []string{"LoadBalancerName", "AvailabilityZone"},
52-
"AWS/ElasticMapReduce": []string{"ClusterId", "JobId"},
53-
"AWS/Kinesis": []string{"StreamName"},
54-
"AWS/ML": []string{"MLModelId", "RequestMode"},
55-
"AWS/OpsWorks": []string{"StackId", "LayerId", "InstanceId"},
56-
"AWS/Redshift": []string{"NodeID", "ClusterIdentifier"},
57-
"AWS/RDS": []string{"DBInstanceIdentifier", "DatabaseClass", "EngineName"},
58-
"AWS/Route53": []string{"HealthCheckId"},
59-
"AWS/SNS": []string{"Application", "Platform", "TopicName"},
60-
"AWS/SQS": []string{"QueueName"},
61-
"AWS/S3": []string{"BucketName", "StorageType"},
62-
"AWS/SWF": []string{"Domain", "ActivityTypeName", "ActivityTypeVersion"},
63-
"AWS/StorageGateway": []string{"GatewayId", "GatewayName", "VolumeId"},
64-
"AWS/WorkSpaces": []string{"DirectoryId", "WorkspaceId"},
43+
"AWS/AutoScaling": {"AutoScalingGroupName"},
44+
"AWS/Billing": {"ServiceName", "LinkedAccount", "Currency"},
45+
"AWS/CloudFront": {"DistributionId", "Region"},
46+
"AWS/CloudSearch": {},
47+
"AWS/DynamoDB": {"TableName", "GlobalSecondaryIndexName", "Operation"},
48+
"AWS/ElastiCache": {"CacheClusterId", "CacheNodeId"},
49+
"AWS/EBS": {"VolumeId"},
50+
"AWS/EC2": {"AutoScalingGroupName", "ImageId", "InstanceId", "InstanceType"},
51+
"AWS/ELB": {"LoadBalancerName", "AvailabilityZone"},
52+
"AWS/ElasticMapReduce": {"ClusterId", "JobId"},
53+
"AWS/Kinesis": {"StreamName"},
54+
"AWS/ML": {"MLModelId", "RequestMode"},
55+
"AWS/OpsWorks": {"StackId", "LayerId", "InstanceId"},
56+
"AWS/Redshift": {"NodeID", "ClusterIdentifier"},
57+
"AWS/RDS": {"DBInstanceIdentifier", "DatabaseClass", "EngineName"},
58+
"AWS/Route53": {"HealthCheckId"},
59+
"AWS/SNS": {"Application", "Platform", "TopicName"},
60+
"AWS/SQS": {"QueueName"},
61+
"AWS/S3": {"BucketName", "StorageType"},
62+
"AWS/SWF": {"Domain", "ActivityTypeName", "ActivityTypeVersion"},
63+
"AWS/StorageGateway": {"GatewayId", "GatewayName", "VolumeId"},
64+
"AWS/WorkSpaces": {"DirectoryId", "WorkspaceId"},
6565
}
6666
}
6767

@@ -81,7 +81,7 @@ func handleGetRegions(req *cwRequest, c *middleware.Context) {
8181

8282
func handleGetNamespaces(req *cwRequest, c *middleware.Context) {
8383
result := []interface{}{}
84-
for key, _ := range metricsMap {
84+
for key := range metricsMap {
8585
result = append(result, util.DynMap{"text": key, "value": key})
8686
}
8787

pkg/api/dataproxy.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,30 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht
6464
return &httputil.ReverseProxy{Director: director}
6565
}
6666

67-
//ProxyDataSourceRequest TODO need to cache datasources
68-
func ProxyDataSourceRequest(c *middleware.Context) {
69-
id := c.ParamsInt64(":id")
70-
query := m.GetDataSourceByIdQuery{Id: id, OrgId: c.OrgId}
67+
var dsMap map[int64]*m.DataSource = make(map[int64]*m.DataSource)
68+
69+
func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
70+
// ds, exists := dsMap[id]
71+
// if exists && ds.OrgId == orgId {
72+
// return ds, nil
73+
// }
7174

75+
query := m.GetDataSourceByIdQuery{Id: id, OrgId: orgId}
7276
if err := bus.Dispatch(&query); err != nil {
77+
return nil, err
78+
}
79+
80+
dsMap[id] = &query.Result
81+
return &query.Result, nil
82+
}
83+
84+
func ProxyDataSourceRequest(c *middleware.Context) {
85+
ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId)
86+
if err != nil {
7387
c.JsonApiErr(500, "Unable to load datasource meta data", err)
7488
return
7589
}
7690

77-
ds := query.Result
7891
targetUrl, _ := url.Parse(ds.Url)
7992
if len(setting.DataProxyWhiteList) > 0 {
8093
if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists {
@@ -83,11 +96,11 @@ func ProxyDataSourceRequest(c *middleware.Context) {
8396
}
8497
}
8598

86-
if query.Result.Type == m.DS_CLOUDWATCH {
99+
if ds.Type == m.DS_CLOUDWATCH {
87100
cloudwatch.HandleRequest(c)
88101
} else {
89102
proxyPath := c.Params("*")
90-
proxy := NewReverseProxy(&ds, proxyPath, targetUrl)
103+
proxy := NewReverseProxy(ds, proxyPath, targetUrl)
91104
proxy.Transport = dataProxyTransport
92105
proxy.ServeHTTP(c.RW(), c.Req.Request)
93106
}

pkg/middleware/logger.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ package middleware
1818
import (
1919
"fmt"
2020
"net/http"
21-
"runtime"
2221
"time"
2322

2423
"github.com/Unknwon/macaron"
2524
"github.com/grafana/grafana/pkg/log"
2625
)
2726

28-
var isWindows bool
29-
30-
func init() {
31-
isWindows = runtime.GOOS == "windows"
32-
}
33-
34-
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
3527
func Logger() macaron.Handler {
3628
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
3729
start := time.Now()
@@ -40,20 +32,17 @@ func Logger() macaron.Handler {
4032
c.Next()
4133

4234
content := fmt.Sprintf("Completed %s %v %s in %v", req.URL.Path, rw.Status(), http.StatusText(rw.Status()), time.Since(start))
43-
if !isWindows {
44-
switch rw.Status() {
45-
case 200:
46-
content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
47-
return
48-
case 304:
49-
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
50-
return
51-
case 404:
52-
content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
53-
case 500:
54-
content = fmt.Sprintf("\033[1;36m%s\033[0m", content)
55-
}
35+
36+
switch rw.Status() {
37+
case 200, 304:
38+
content = fmt.Sprintf("%s", content)
39+
return
40+
case 404:
41+
content = fmt.Sprintf("%s", content)
42+
case 500:
43+
content = fmt.Sprintf("%s", content)
5644
}
45+
5746
log.Info(content)
5847
}
5948
}

0 commit comments

Comments
 (0)