@@ -46,7 +46,7 @@ import (
46
46
47
47
type EnvironmentService interface {
48
48
FindOne (environment string ) (* bean2.EnvironmentBean , error )
49
- GetDataSourceName (environment string ) (string , error )
49
+ GetDataSourceName (environment string ) (dataSourceData DataSourceMetaData , err error )
50
50
Create (mappings * bean2.EnvironmentBean , userId int32 ) (* bean2.EnvironmentBean , error )
51
51
Update (mappings * bean2.EnvironmentBean , userId int32 ) (* bean2.EnvironmentBean , error )
52
52
GetAllActive () ([]bean2.EnvironmentBean , error )
@@ -106,25 +106,33 @@ func NewEnvironmentServiceImpl(environmentRepository repository.EnvironmentRepos
106
106
}
107
107
}
108
108
109
- func (impl EnvironmentServiceImpl ) GetDataSourceName (environment string ) (string , error ) {
109
+ func (impl EnvironmentServiceImpl ) GetDataSourceName (environment string ) (DataSourceMetaData , error ) {
110
+ datasource := DataSourceMetaData {}
110
111
model , err := impl .environmentRepository .FindOne (environment )
111
112
if err != nil {
112
113
impl .logger .Errorw ("error in fetching environment" , "err" , err )
113
- return "" , err
114
+ return datasource , err
114
115
}
115
116
if model .GrafanaDatasourceId == 0 {
116
- return "" , fmt .Errorf ("prometheus endpoint not found" )
117
+ return datasource , fmt .Errorf ("prometheus endpoint not found" )
117
118
} else {
118
119
impl .logger .Debugw ("environment datasource name" , "datasource" , model .GrafanaDatasourceId )
119
- datasource , err := impl .grafanaClient .GetDatasource (model .GrafanaDatasourceId )
120
+ data , err := impl .grafanaClient .GetDatasource (model .GrafanaDatasourceId )
120
121
if err != nil {
121
122
impl .logger .Errorw ("error in fetching datasource" , "err" , err )
122
- return "" , err
123
+ return datasource , err
123
124
}
124
- return datasource .Name , nil
125
+ datasource .Name = data .Name
126
+ datasource .Id = model .GrafanaDatasourceId
127
+ return datasource , nil
125
128
}
126
129
}
127
130
131
+ type DataSourceMetaData struct {
132
+ Id int
133
+ Name string
134
+ }
135
+
128
136
func (impl EnvironmentServiceImpl ) Create (mappings * bean2.EnvironmentBean , userId int32 ) (* bean2.EnvironmentBean , error ) {
129
137
existingEnvs , err := impl .environmentRepository .FindByClusterId (mappings .ClusterId )
130
138
if err != nil && ! util .IsErrNoRows (err ) {
0 commit comments