github.com/google/cloudprober@v0.11.3/targets/file/file.go (about)

     1  // Copyright 2020-2021 The Cloudprober Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  /*
    16  Package file implements a file-based targets for cloudprober.
    17  */
    18  package file
    19  
    20  import (
    21  	"context"
    22  
    23  	"github.com/google/cloudprober/logger"
    24  	"github.com/google/cloudprober/rds/client"
    25  	client_configpb "github.com/google/cloudprober/rds/client/proto"
    26  	"github.com/google/cloudprober/rds/file"
    27  	file_configpb "github.com/google/cloudprober/rds/file/proto"
    28  	rdspb "github.com/google/cloudprober/rds/proto"
    29  	configpb "github.com/google/cloudprober/targets/file/proto"
    30  	dnsRes "github.com/google/cloudprober/targets/resolver"
    31  )
    32  
    33  // New returns new file targets.
    34  func New(opts *configpb.TargetsConf, res *dnsRes.Resolver, l *logger.Logger) (*client.Client, error) {
    35  	lister, err := file.New(&file_configpb.ProviderConfig{
    36  		FilePath: []string{opts.GetFilePath()},
    37  	}, l)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	clientConf := &client_configpb.ClientConf{
    43  		Request:   &rdspb.ListResourcesRequest{Filter: opts.GetFilter()},
    44  		ReEvalSec: opts.ReEvalSec,
    45  	}
    46  
    47  	return client.New(clientConf, func(_ context.Context, req *rdspb.ListResourcesRequest) (*rdspb.ListResourcesResponse, error) {
    48  		return lister.ListResources(req)
    49  	}, l)
    50  }